我尝试在条件格式的公式中使用 2 个条件和函数,但没有成功...
下面是我的代码,但我在公式部分有问题。
感谢您的帮助。
Columns("Y:Y").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=AND(ISNUMBER($J1);ISNUMBER($J2);$Y1<>$Y2)"
With Selection.FormatConditions(1)
.Font.Color = RGB(174, 37, 42)
.Interior.Color = RGB(255, 200, 205)
End With
Selection.FormatConditions(1).StopIfTrue = False
答案 0 :(得分:0)
.FormatConditions.Delete
,您可以确保所应用的条件格式是唯一的。.FormatConditions.Delete
。1
而不是 .FormatConditions.Count
(最后添加的 CF)。但是为什么要麻烦,因为显式编号可能只在有多种格式时才有用。Option Explicit
Sub cfTest()
With Columns("Y")
.FormatConditions.Delete ' Remove any previous conditional formatting.
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=AND(ISNUMBER($J1);ISNUMBER($J2);$Y1<>$Y2)"
With .FormatConditions(.FormatConditions.Count) ' just added CF
.Font.Color = RGB(174, 37, 42)
.Interior.Color = RGB(255, 200, 205)
.StopIfTrue = False
End With
End With
End Sub