VBA中的多个条件格式化variables

这是我现在所拥有的:

'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部分的工作。

我相信我在上面的评论中所做的公式调整应该可以解决您的问题,但这里是我如何清理logging的条件格式代码。

 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)... )使其更具可读性。