Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

excel - Using VBA to detect which decimal sign the computer is using

Is it possible to use VBA to detect which decimal sign is being used on the computer?

I have a macro script that adds a conditional formatting to an excel sheet. The problem is that the target computers might use both decimal signs. So I want to make the script work for all computers.

The code looks like this:

With range("D" & row)
    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlCellValue, Operator:=xlNotBetween, Formula1:="=1,01*$C$" & row, Formula2:="=0,99*$C$" & row
    .FormatConditions(1).Font.ColorIndex = 3
End With
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Regarding the answer above, it is important to know that Application.DecimalSeparator and Application.International(xlDecimalSeparator) do not behave the same way:

  • Application.DecimalSeparator will ALWAYS output the decimal separator chosen in Excel options even when Excel is told to use System Separators (from Windows regional settings)
  • Application.International(xlDecimalSeparator) will output whatever is the actual decimal separator used by Excel whether it comes from Windows settings (when Application.UseSystemSeparators = True) or from Excel options (when Application.UseSystemSeparators = False)

I therefore strongly recommend to always use Application.International(xlDecimalSeparator).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...