"Decimal point is comma", How can I do this in VBA ?

Anoniem
2023-02-21T18:22:36+00:00

I must convert using VBA lots of US formatted numerical Data e.g. 12,258.369 into 12.258,369 what code/format should I use?

Microsoft 365 en Office | Excel | Overige | Windows

Vergrendelde vraag. Deze vraag is gemigreerd vanuit de Microsoft Ondersteuning-community. U kunt met een stem aangeven of de inhoud nuttig is, maar u kunt geen opmerkingen of antwoorden toevoegen of de vraag volgen.

0 opmerkingen Geen opmerkingen
Antwoord geaccepteerd door vraagauteur
Anoniem
2023-02-23T08:21:04+00:00

It's no problem Jan, we are here to help, please try this again:

Sub ConvertFormat()

Dim originalValue As String Dim convertedValue As String

originalValue = "1,234.56" 'Replace with your own data

' Replace decimal point with comma convertedValue = Replace(originalValue, ".", "#") convertedValue = Replace(convertedValue, ",", ".") convertedValue = Replace(convertedValue, "#", ",")

' Output the converted value to the Immediate Window Debug.Print convertedValue

End Sub

Was dit antwoord nuttig?

1 persoon vond dit antwoord nuttig.
0 opmerkingen Geen opmerkingen

8 extra antwoorden

Sorteren op: Nieuwste
  1. Anoniem
    2023-02-22T17:59:26+00:00

    Jan,

    Wellicht dat je hier wat mee kunt.

    Ik veronderstel dat je data in US-format in A2:A700 staan.

    Dan kun je deze code gebruiken voor de omzetting:

    Sub OmzettenUSformat() 
    
        Dim sh As Worksheet 
    
        Dim rng As Range 
    
        Set sh = Worksheets("Blad1") 
    
        For Each rng In sh.Range("A2:A700") 
    
            rng.Offset(0, 1) = --Replace(Replace(rng, ",", ""), ".", ",") 
    
            rng.Offset(0, 1).NumberFormat = "#,##0.#####" 
    
        Next 
    
    End Sub 
    

    Jan

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen
  2. Anoniem
    2023-02-22T15:48:51+00:00

    Your solution is not exactly what I need! Sorry. All figures come out with only"," everywhere.

    I wanted to instruct VBA to use the European way of writing Decimal numbers and not the US!

    In some Computer languages it was sufficient to use the instruction "Decimal point is comma" once in your code. But too bad.

    I can give you some examples : 201.6 should become 206,6; 65.3697 should be translated into 65,3697 but 1,235.75 should be tranlated into1.235,75 and 2850.25 must result in 2850,25 (or 2.850,25 is also correct) and so on! I hope this is more clear than my first question.

    I think Format(OriginalValue, "#,#") is also possible, but i'm not sure it will always work?

    Coul you help me out.

    Thanks in advance

    Jan.

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen
  3. Anoniem
    2023-02-21T21:33:15+00:00

    Zal niet lukken maar probeer eens de juiste taal in een Nederlandstalig forum

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen
  4. Anoniem
    2023-02-21T19:02:50+00:00

    Hi Jmav

    I'm AnnaThomas and I'd be happy to help you with your question. In this Forum, we are Microsoft consumers just like yourself.

    Here is an example:

    Sub ConvertFormat() Dim originalValue As String Dim convertedValue As String

    originalValue = "12,258.369" ' replace with your own data

    ' Replace decimal point with comma convertedValue = Replace(originalValue, ".", ",")

    ' Replace comma with decimal point convertedValue = Replace(convertedValue, ",", ".")

    ' Output the converted value to the Immediate Window Debug.Print convertedValue End Sub

    I hope this helps ;-), let me know if this is contrary to what you need, I would still be helpful to answer more of your questions.

    Best Regards,

    AnnaThomas

    Give back to the community. Help the next person with this problem by indicating whether this answer solved your problem. Click Yes or No at the bottom.

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen