如何在逗号是小数分隔符的情况下应用条件格式

How to apply conditional formatting where comma is the decimal separator

应用条件格式的代码。当 range.value 低于 7,2 时保持白色,高于 8,1 时变为红色。
此代码在我的笔记本电脑上运行。在另一台计算机上,它会抛出此错误。

Run-time error '5':
Invalid procedure call or argument

Private Sub totalEPS(mySelection As Range)
    With mySelection.FormatConditions
        .Delete
        With .Add(Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="=7,2")
            .Interior.Color = 65535
            .StopIfTrue = False
        End With
        With .Add(Type:=xlCellValue, Operator:=xlGreater, Formula1:="=8,1")
            .Interior.Color = 255
            .StopIfTrue = False
        End With
    End With
End Sub

在另一台电脑上的调试在行中停止

With .Add(Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="=7,2")

我怀疑它与小数点分隔符有关 - 在 en-US 操作系统上逗号是一个点。

尝试将此函数添加到您的模块中:

Public Function LocalizeDecimal(ByVal value As Double) As String
    LocalizeDecimal = Replace(Str(value), ".", Application.International(xlDecimalSeparator))
End Function

然后将 Formula1 参数编辑为如下内容:

With .Add(Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="=" & LocalizeDecimal(7.2))

并且:

With .Add(Type:=xlCellValue, Operator:=xlGreater, Formula1:="=" & LocalizeDecimal(8.1))