为什么条件格式只有在我在编辑栏内单击后才会出现?

Why does the Conditional format Not take until I click inside the formula bar?

我在 VBA 中为条件格式生成公式如下

'''Range("H2").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=H2<F2"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
    .Color = -16776961
    .TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
    .Pattern = xlNone
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=H2>=F2"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent6
    .TintAndShade = 0.599963377788629
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.Copy
Range("H3:H4000").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    
Application.CutCopyMode = False'''

当我以这种方式设置格式时,直到我点击该单元格的公式输入字段,然后点击退出它,结果才会出现。查看公式的图片,点击进入前的样子,以及点击进入和退出后的样子。enter image description here

"The result does not take until I click into the formula entry field for that cell, and then click out of it."

这通常是将数字存储为文本的症状。

您可以使用此 paste-special trick.

将它们转换为真实数字

或者您可以使用双一元 --:

在条件格式规则中将它们强制转换为数字
=--H2<--F2