VBA中的多个条件格式变量
以下是我目前掌握的情况:VBA中的多个条件格式变量,vba,excel,excel-formula,conditional-formatting,Vba,Excel,Excel Formula,Conditional Formatting,以下是我目前掌握的情况: '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
'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。。。使其更具可读性。将其更改为公式1:==和$N4=19,$R4=OR,效果完美,并能够根据我的需要进一步修改它。谢谢