Excel VBA-条件格式,索引不包括在间隔中
我有一段代码,它给我的错误索引不包括在Excel VBA-条件格式,索引不包括在间隔中,excel,vba,Excel,Vba,我有一段代码,它给我的错误索引不包括在.FormatConditions(Selection.FormatConditions.Count)行中的间隔中。SetFirstPriority With students.Range(MyNegRange) .FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _ Formula1:="="&qu
.FormatConditions(Selection.FormatConditions.Count)行中的间隔中。SetFirstPriority
With students.Range(MyNegRange)
.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=""x""", Formula2:="=""x"""
.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13311 'rosso
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
End With
我想将包含“x”的单元格涂成红色,但仅在特定范围内。我使用了宏记录器,然后尝试调整代码,我不知道为什么会出现错误。您可以通过按
格式条件使代码更可读。将添加到With
块中:
与students.Range(MyNegRange).FormatConditions.Add(_
类型:=xlCellValue,运算符:=xlBetween_
公式1:=“=”“x”“”,公式2:=“=”“x”“”)
.SetFirstPriority
带.内饰
.PatternColorIndex=xlAutomatic
.Color=13311
.TintAndShade=0
以
.StopIfTrue=False
以
这样,代码的其余部分就被限定在刚刚添加的FormatCondition
对象的范围内删除选择项
(它的两个实例)。很好,现在可以完美地工作了!