使用VBA中的格式条件检查"false"的值是否在范围内



这里的快速问题,我一直在寻找如何在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

这就是如何使用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

最新更新