CravingGod
New Member
- Joined
- Dec 31, 2014
- Messages
- 7
Novice here. I'm sure it's simple. I have some previously existing code that works fine, but I think I need to add either an "if" statement or an "and" statement to the formula somehow.
I have a report that is generated and the code below provides conditional formatting if H>G starting on row 3. I only need this rule to apply if the corresponding cell in column K contains "Pipe".
Thanks in advance.
I have a report that is generated and the code below provides conditional formatting if H>G starting on row 3. I only need this rule to apply if the corresponding cell in column K contains "Pipe".
Thanks in advance.
Code:
' Conditional format columns G:H where H>G
Range("H3").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$H3>$G3"
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("G3:H3,G3:H1048576").Select
Range("H3").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$H3>$G3"
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("G1:H2").Select
Selection.FormatConditions.Delete