VBA Conditional Formatting

jjlafond

Board Regular
Joined
Jul 17, 2014
Messages
56
Hello,

Is it possible to apply conditional formatting & borders to cells without highlighting / selecting them?
ie. Can I apply conditional formatting (CF) & borders by using .Activate or something similar (instead of .Select)?

I am applying several different CFs to a small range right now by selecting them (using vba). But it is very slow, taking 5-10 seconds to complete, and I can actually watch every step happening.

I will be using the same CFs on a much larger range soon, so I want to speed it up considerably (otherwise i'll have to take a lucn break before it finishes running :hungry:).





An example of my current conditional formatting:ActiveCell.Resize(6, 1).Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotBetween, _
Formula1:="=$M$6", Formula2:="=$L$6"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

An example of my current formatting:
ActiveCell.Resize(6, NumCav).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)..... 'more border conditions follow.

There is a lot more of this going on too....
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try like this

Code:
With ActiveCell.Resize(6, 1)
    .FormatConditions.Add Type:=xlCellValue, Operator:=xlNotBetween, _
    Formula1:="=$M$6", Formula2:="=$L$6"
    .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With .FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
    End With
    .FormatConditions(1).StopIfTrue = False
End With
 
Upvote 0
Thank you, this does speed it up some.

It is still somewhat slow, but now the program does not have to take the time to highlight everything then apply formatting, it skips over the visible highlight.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top