"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: Meest nuttig
  1. Anoniem
    2023-02-23T08:55:19+00:00

    Splendid, Thanks! But what is the purpose of "vbnet"? I had to comment it. But anyhow, your solution works!

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen
  2. Anoniem
    2023-02-23T07:56:49+00:00

    Sorry,  I Simply want to convert this type of US data into this EUROPEAN numerical form:

    INPUT:     Expected OUTPUT

      201.5                     201,5

      201.55                   201,55

      201.555                 201,555

      201.5555               201,5555

    1,234.56                1.234,56

    Simply "." become "," and the other way arround.

    I can handle them in batch or one by one.

    Sorry for the problems

    Jan

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen
  3. Anoniem
    2023-02-23T07:55:26+00:00

    Sorry, I Simply want to convert this type of US data into this EUROPEAN numerical form:

    INPUT: Expected OUTPUT

    201.5 201,5

    201.55 201,55

    201.555 201,555

    201.5555 201,5555

    1,234.56 1.234,56

    Simply "." become "," and the other way arround.

    I can handle them in batch or one by one.

    Sorry for the problems

    Jan

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen
  4. Anoniem
    2023-02-22T18:18:17+00:00

    To instruct VBA to use the European way of writing decimal numbers, you can set the application's Decimal Separator to a comma (",") using the Application.DecimalSeparator property. You can then use the Format function to format the numerical data in the desired way.

    Here's an example code that shows how to do this:

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

    ' Set the decimal separator to comma Application.DecimalSeparator = ","

    ' Replace decimal point with decimal separator originalValue = CDbl("12,258.369")

    ' Format the value with the desired number of decimal places convertedValue = Format(originalValue, "#,##0.000")

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

    End Sub

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen