Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using VBA to detect which decimal sign the computer is using

Tags:

excel

vba

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
like image 773
Wai Wong Avatar asked Dec 18 '13 07:12

Wai Wong


People also ask

How do I use VBA symbol?

When you are in the Insert->Symbol Dialog and you select the symbol you want to insert, you'll see at the bottom of the Dialog the hexadecimal character code of the symbol. You can use the codes to write the characters in strings or directly in cells.

How do you round decimals in VBA?

Example #1 – VBA Round Function to Round a NumberStep 1: Insert a new module under Visual Basic Editor (VBE). Step 2: Define a new sub-procedure to store a macro in VBE. Step 4: Now, add “& Round (10.9834, 2)” in front of MsgBox command, so that the rounded value will be shown up in the message box along.

Does VBA round up or down?

Similar to the Worksheet function, where we round up the numbers to the closest integers, in VBA, we have a RoundUp function which decreases the decimal point for us. The syntax for the RoundUp function is as follows Round up (Number, Number of Digits After Decimal).

Why is VBA rounding up?

If the number of digits provided is greater than zero then the number is rounded up to the specified decimal place. If the number of digits is provided as input is equal to zero then the number is rounded up to its nearest integer.


1 Answers

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).

like image 109
alfromFR29 Avatar answered Sep 23 '22 04:09

alfromFR29