条件格式(精确标准和多列)

Conditional formatting (exact criteria and multiple columns)

我是一个 excel vba 新手,我对这段代码非常困惑,我需要格式化包含多列特定条件的单元格。

例如,我需要用粗体红色字体将除包含 "Complete" 的单元格以外的所有值突出显示为黄色。

我试图通过简单地过滤掉 "Complete" 并突出显示所有其他值来记录它,但我需要它是动态的。

Sub Macro1()

ActiveSheet.Range("$A:$W14").AutoFilter Field:=6, Criteria1:= _
    "=Incomplete", Operator:=xlOr, Criteria2:="="
Range("F171").Select
Range(Selection, Selection.End(xlDown)).Select
Range("F171:F6114").Select
With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With
With Selection.Font
    .Color = -16776961
    .TintAndShade = 0
End With
Selection.Font.Bold = True
End Sub

如有任何帮助,我们将不胜感激!

试试这个:

Sub Macro1()

Dim rng As Range
Set rng = ActiveSheet.Range("A1").CurrentRegion

With rng

.AutoFilter Field:=6, Criteria1:="<>Complete", Operator:=xlAnd

End With

With rng.Range(Cells(2, 6), Cells(rng.Rows.Count, 6)).SpecialCells(xlCellTypeVisible)

    With .Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = vbYellow
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With

    With .Font
        .Color = vbRed
        .TintAndShade = 0
        .Bold = True
    End With

End With

End Sub