Conditional formating

Y

Yogin

Hi i'm using the code below for conditional formating, this work fine but is
there a code where if I chose a criteria which is not in the code to change
the colour to default (white). Currently I am using validation box and has
upto 16 different criteria, if I type in LEX, this changes the cell colour to
Red, but if i change the same cell value to LL, the cell colour is still Red
and not white.

Can you anyone help me please.

Private Sub Worksheet_Change(ByVal Target As Range)

Const WS_RANGE As String = "G7:HC600"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case "LEX": .Interior.ColorIndex = 3 'red
Case "LIN": .Interior.ColorIndex = 6 'yellow

End Select
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub

Thanks

Yogin
 
D

Dave Peterson

Just add a line:

Select Case .Value
Case "LEX": .Interior.ColorIndex = 3 'red
Case "LIN": .Interior.ColorIndex = 6 'yellow
Case Else: .Interior.ColorIndex = xlNone
End Select
 
Y

Yogin

Thanks Dave,
This worked perfectly.

Yogin

Dave Peterson said:
Just add a line:

Select Case .Value
Case "LEX": .Interior.ColorIndex = 3 'red
Case "LIN": .Interior.ColorIndex = 6 'yellow
Case Else: .Interior.ColorIndex = xlNone
End Select
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top