Warm tip: This article is reproduced from serverfault.com, please click

How do I change decimal dot into decimal comma?

发布于 2020-11-28 14:04:13

I have a column containing numbers with mixed decimal separators.
example

I need to use "," as separator.

How do I change dot into comma?

With ThisWorkbook.Worksheets("RAW").Range("A1")
    .Value = Replace(.Value, ".", ",")
End With

The point is stored as text
look at it

Is there any way to store it as general/numeric?

I tried this

With ThisWorkbook.Worksheets("RAW").Range("A1")
    .NumberFormat = "General"
    .Value = Replace(.Value, ".", ",")
    .NumberFormat = "General"
    .Value = .Value
End With
Questioner
k.Sz
Viewed
0
JvdV 2020-11-28 23:35:54

A single cell could be solved quick and dirty through:

.Value = Replace(.Value, ".", ",")*1

Or:

.Value = CSng(Replace(.Value, ".", ","))

If you happen to have a range to process, you could use:

Sub Test()

With ThisWorkbook.Worksheets("RAW").Range("A1:A3")
    .Replace ".", ","
    .TextToColumns
End With

End Sub

Per column:

Sub Test()

With ThisWorkbook.Worksheets("RAW").Range("C2:D4")
    .Replace ".", ","
    For Each col In .Columns
        col.TextToColumns
    Next
End With

End Sub