简体   繁体   English

Excel小数点分隔符根据区域设置的不同行为

[英]Excel decimal separator behaves differently based on regional setting

I have an excel which there are some values with decimals. 我有一个excel,其中有一些小数值。 The values are strings , and since many countries are using it, some countries use "," comma for decimal places, others use "." 值是字符串 ,由于许多国家/地区都在使用它,因此某些国家/地区使用“,”逗号表示小数位,其他国家/地区使用“。” dot for decimal places. 点到小数位。

Once all the data worldwide is compiled, people from different regional areas process the data with macros. 一旦编译了全世界的所有数据,来自不同区域的人员就会用宏处理数据。

In order for people to use same settings, I change in the macro their decimalseparator to be all the same: 为了让人们使用相同的设置,我将它们的decimalseparator更改为完全相同:

Application.UseSystemSeparators = False
Application.DecimalSeparator = ","
application.ThousandsSeparator = "."

I then run certain macros to add the values together and this is where the problem begins. 然后我运行某些宏来将值添加到一起,这就是问题开始的地方。 For people in europe the macro works perfectly. 对于欧洲人来说,宏观工作非常完美。 The macro first converts any dots to commas like this (note that the cell value is a string): 宏首先将任何点转换为这样的逗号(注意单元格值是一个字符串):

If InStr(NW.Cells(ttt, 100), ".") > 0 Then
       x2 = Replace(NW.Cells(ttt, 100), ".", ",")
       NW.Cells(ttt, 100) = x2
End If

So if NW.Cells(ttt, 100) = 12.25 it converts it to 12,25 then it runs further macros (adding all values together). 因此,如果NW.Cells(ttt,100)= 12.25,它将其转换为12,25,然后它运行更多的宏(将所有值加在一起)。

But if a person in USA runs the macro, the 12.25 becomes 1225 但如果一个人在美国运行宏,12.25就变成了1225

Since I have changed the application.decimalsepator to "," at the beginning of the macro, I don't understand why the macro behaves differently... 由于我在宏的开头将application.decimalsepator更改为“,”,我不明白为什么宏的行为不同......

Any ideas how to solve this ? 任何想法如何解决这个问题?

Note Excel 2007 and Excel 2010 is being used so cannot use the =NUMBERVALUE function... 注意正在使用Excel 2007和Excel 2010,因此无法使用= NUM​​BERVALUE函数...

thanks 谢谢

Sub changeSeparators()
Dim myRange As Range
Dim rng As Range

Set myRng = ActiveSheet.Range("A1:A500")

For Each rng In myRng
   rng.Value = Replace(rng.Value, "'", ",")
   If Left(Right(rng.Value, 3), 1) = "," Then
       rng.Value = Mid(rng.Value, 1, Len(rng.Value) - 3) & "." & Right(rng.Value, 2)
   End If
Next rng
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM