快速提问这些人,我一直在寻找如何在VBA中使用formatConditions而我找不到我想要的东西。
我知道如何在excel中制定新规则,但我必须通过VBA制作这个规则。
我会尝试用我的代码评论来解释这个:
With Range(Cells(5, 11), Cells(comparisonlastrow, 11))
.FormatConditions.Delete
'Add formatcondition rule saying that if a cell in this range contains "false", this cell goes vbRed
'.
End With
Next
答案 0 :(得分:1)
这是使用VBA
添加条件格式的方法。您可以使用示例代码稍微玩一下来获得所需的输出。
FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=FALSE"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
首先编辑:
我假设你想在某个范围内应用条件格式(循环类型),这就是你可以做的事情
Sub Cformatting()
Dim i
For i = 1 To 1000
Range("E" & i).Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=FALSE"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Next
End Sub