简体   繁体   中英

Excel: Using VBA to apply conditional formatting to blank cells in individula columns

I have applied the duplicate conditional format to columns AB, AD, AR, AT, BH & BJ across a worksheet with around 1500 rows, however it is also highlighting the blanks.

I have tried to create an additional conditional format of changing any of the blanks to a white cell colour, as I can't find a way to remove the conditional format from the blank cells.

The only way I have found to highlight the cells white at the moment is to use the conditional formatting again, which works perfectly when I record the macro but not when I replay this as it turns either the whole column white, or leaves blank cells as red.

This is the vba code of the additional conditional format:

Sub Macro3()    
    Range("I:I,AB:AB,AD:AD,AR:AR,AT:AT,BH:BH,BJ:BJ").Select
    Range("BJ1").Activate
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=LEN(TRIM(BJ1))=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False

End Sub

Help is greatly appreciated as I've spent far too long trying to find a work around!

尝试为同一单元格添加另一个公式为isblank=true过滤器。

Try this

Sub Macro3()
    Range("I:I,AB:AB,AD:AD,AR:AR,AT:AT,BH:BH,BJ:BJ").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=LEN(TRIM(I1))=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM