VBA changing decimal to comma automaticaly

荒凉一梦 提交于 2019-12-05 22:19:34

This is a normal behavior on German systems with German default locale Windows settings (comma as decimal separator and point as thousand separator in Windows settings).

MsgBox .Cells(25, 2).Value

returns the value with the format of the Windows locale default.

The Application.DecimalSeparator that you set in your Excel options affects what is displayed in the cell, but not what is displayed by message boxes.

Therefore you can use

MsgBox .Cells(25, 2).Text

which returns the value as text formatted like in the cell.


Another workaround is to replace the commas with replace() function:

MsgBox Replace(.Cells(25, 2).Value, ",", ".")

One of the first functions I have created, after I came to Germany was this one:

Public Function change_commas(ByVal myValue As Variant) As String

    Dim str_temp As String

    str_temp = CStr(myValue)
    change_commas = Replace(str_temp, ",", ".")

End Function

Since the last 2 years it is present in every VBA project. Although I have changed my style of writing function names and variables, this one has stayed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!