Search code examples
excelvbadecimalseparator

How do I change decimal dot into decimal comma?


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

Solution

  • 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