VBA 中的多个条件格式变量
Multiple Conditional Formatting Variables in VBA
这是我目前得到的:
'Highlight If N=19 & R=OR
Range("G4:R1000").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$N4=19"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
我正在尝试根据多个条件突出显示一些单元格。如果 N=19 且如果 R=OR。我只能让 N=19 部分工作。
我相信我在上面的评论中所做的公式调整应该可以解决您的问题,但这是我清理记录的条件格式代码的方法。
With Worksheets("Sheet1")
With .Range("G4:R1000")
With .FormatConditions.Add(Type:=xlExpression, Formula1:="=AND($N4=19, $R4=""OR"")")
With .Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
.SetFirstPriority
End With
.FormatConditions(1).StopIfTrue = True
End With
End With
删除冗长的限定代码(例如 Selection.FormatConditions(Selection.FormatConditions.Count)...
)使其更具可读性。
这是我目前得到的:
'Highlight If N=19 & R=OR
Range("G4:R1000").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$N4=19"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
我正在尝试根据多个条件突出显示一些单元格。如果 N=19 且如果 R=OR。我只能让 N=19 部分工作。
我相信我在上面的评论中所做的公式调整应该可以解决您的问题,但这是我清理记录的条件格式代码的方法。
With Worksheets("Sheet1")
With .Range("G4:R1000")
With .FormatConditions.Add(Type:=xlExpression, Formula1:="=AND($N4=19, $R4=""OR"")")
With .Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
.SetFirstPriority
End With
.FormatConditions(1).StopIfTrue = True
End With
End With
删除冗长的限定代码(例如 Selection.FormatConditions(Selection.FormatConditions.Count)...
)使其更具可读性。