Need help with multiple conditional formatting

butters149

New Member
Joined
Mar 21, 2018
Messages
23
Hello,

I am trying to modify my VBA to do multiple conditional formatting but it doesn't seem to work. Below is the code and the two outcomes I like. Can anyone please help? Thank you.

1.) Highlight range of row cells if column R is more than 60
AND
2.) Highlight range of row cells if column R and L meet criteria of $R2>45,$L2>100000

Range("E2:R2").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$R2>60"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND($R2>45,$L2>100000)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("A1").Select
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
It looks like you have only written the formulas to apply to row 2 only.
How many rows do you want to apply this to?
How can we determine which row to go down to?
 
Upvote 0
It looks like you have only written the formulas to apply to row 2 only.
How many rows do you want to apply this to?
How can we determine which row to go down to?
Ah ok I wanted it from columns E2 through R2, excluding the first row because of the title and go down until no more available data.
 
Upvote 0
For rows with data, does column E always have something in it?
If not, is there some other column that will always have some value in it for all the non-blank rows?
 
Upvote 0
Assuming that column E can be used, then try this code (both conditions can be combined into one, since they are applying the same format):
VBA Code:
    With Range("E2:R" & Cells(Rows.Count, "E").End(xlUp).Row)
        .FormatConditions.Add Type:=xlExpression, Formula1:="=OR($R2>60,AND($R2>45,$L2>100000))"
        .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 49407
            .TintAndShade = 0
        End With
        .FormatConditions(1).StopIfTrue = False
    End With
 
Upvote 0
Solution
Assuming that column E can be used, then try this code (both conditions can be combined into one, since they are applying the same format):
VBA Code:
    With Range("E2:R" & Cells(Rows.Count, "E").End(xlUp).Row)
        .FormatConditions.Add Type:=xlExpression, Formula1:="=OR($R2>60,AND($R2>45,$L2>100000))"
        .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 49407
            .TintAndShade = 0
        End With
        .FormatConditions(1).StopIfTrue = False
    End With
Thank you! this worked.
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

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