Create Conditional Formatting via Code

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
On a newly created sheet I include formulas in Column V. I need to Highlight ALL cells where the formula produces "DUP TRANS"... the following 2 lines are not acheiving this. How can I alter them to acheive my goal?

TIA,

Jim

Code:
'****************************************
Range("V:V").FormatConditions.Delete
Range("V2:V" & LR).FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=$V2=""DUP TRANS"""

'****************************************
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I more completed the code with this code. Once I incorporate it into my procedure I'm getting a R/T 9 error Subscript out of range on line in RED. Any ideas? Tks, Jim


Rich (BB code):
Range("V2:V" & LR).FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=$V2=""DUP TRANS"""
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0.399945066682943
    End With
    Selection.FormatConditions(1).StopIfTrue = False
 
Upvote 0
Got it -- Thanks... Jim

Code:
'****************************************
Range("V2:V" & LR).Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=$V2=""DUP TRANS"""
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0.399945066682943
    End With
    Selection.FormatConditions(1).StopIfTrue = False
'End With
'****************************************
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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