使用VBA中的FormatConditions检查值“false”是否在一个范围内

在这里快速的问题,家伙,我一直在寻找如何在VBA中使用formatConditions,我没有find我想要的。

我知道如何在excel中创build新的规则,但是我必须通过VBA来创build这个规则。

我将尝试用我的代码的注释来解释这一点:

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 

第一编辑:

我假设你想对某个范围(循环types)应用条件格式,这是你可以做的

 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