More than 3 Conditions for formatting

D

Dan

I would like to be able to use conditional formatting for more than 3
conditions. Any suggestions?

Thanks
 
B

Bob Phillips

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1:H10" '<=== change to suit

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 1: .Interior.ColorIndex = 3 'red
Case 2: .Interior.ColorIndex = 6 'yellow
Case 3: .Interior.ColorIndex = 5 'blue
Case 4: .Interior.ColorIndex = 10 'green
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
D

DaveO

Sometimes you can by using AND() and OR() operators if your conditions
are not mutually exclusive- basically combining two or more conditions
into one. Please post your desired conditions.
 
R

roadkill

I don't know if this will help but you actually get 4 formats (the 3 that you
define via conditions that you set with conditional formatting and then the
"default" format, i.e. the format of the cell if none of the conditions are
met).
Will
 
D

Dan

Thank you to everyone!

roadkill said:
I don't know if this will help but you actually get 4 formats (the 3 that you
define via conditions that you set with conditional formatting and then the
"default" format, i.e. the format of the cell if none of the conditions are
met).
Will
 

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