0

Here's what I've got at the moment:

'Highlight If N=19 & R=OR
Range("G4:R1000").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$N4=19"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True

I am trying to highlight a few cells based on multiple criteria. If N=19 and if R=OR. I can only get the N=19 portion to work.

2
  • 1
    Change it to Formula1:="=AND($N4=19, $R4=""OR"")" Commented Mar 22, 2017 at 14:41
  • Works perfectly and was able to further modify it to my needs. Thanks! Commented Mar 22, 2017 at 18:58

1 Answer 1

1

I believe the formula adjustment I made in comments above should solve your problem but here is how I clean up recorded Conditional Formatting code.

With Worksheets("Sheet1")
    With .Range("G4:R1000")
        With .FormatConditions.Add(Type:=xlExpression, Formula1:="=AND($N4=19, $R4=""OR"")")
            With .Interior
                .PatternColorIndex = xlAutomatic
                .Color = 255
                .TintAndShade = 0
            End With
            .SetFirstPriority
        End With
        .FormatConditions(1).StopIfTrue = True
    End With
End With

Removing the verbose qualifying code (e.g. Selection.FormatConditions(Selection.FormatConditions.Count)...) makes it much more readable.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.