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
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.
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.
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).
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.
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)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With