Private Sub Workbook_Open()
Dim lastRow As Long
With Worksheets("Sheet1")
.Cells.FormatConditions.Delete 'DELETE ALL COND FORMATTING
lastRow = .Rows.Count
With .Range("A3:O" & lastRow) 'SET default object, all expressions starting with
'"." will refer to it. Note nested "With"
.Select 'to set ActiveCell to top left corner of the range
.FormatConditions.Add Type:=xlExpression, Formula1:="=COUNTIF($E$3:$E3,$E3)>1"
.FormatConditions(1).Interior.ColorIndex = 44
.FormatConditions(1).StopIfTrue = True
.FormatConditions.Add Type:=xlExpression, Formula1:="=COUNTIF($E$3:$E$" & lastRow & ",$E3)>1"
.FormatConditions(2).Interior.ColorIndex = 37
.FormatConditions.Add Type:=xlExpression, Formula1:="=UPPER($K2) = ""YES"""
.FormatConditions(3).Interior.Color = vbRed 'Red
End With
End With
End Sub
|