how do i set more than three conditions in condition formatting?

S

senpm

I need to set up color coding for five different conditions - can you help me?
if A1 cell value is greater than or equal to 6 then color yellow
if A1 cell value is between 5 and 6 then color silver
if A1 cell value is between 4 and 5 then color blue
if A1 cell value is less than 4 then color red
if A1 cell value has no value (entered) then color cyan

can we do this with conditional formatting or do we need VB for this? if vb
is needed can i get some idea how to create the code...

i am not good at coding...please help me....
 
B

Bob Phillips

You need VBA


'-----------------------------------------------------------------
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 "": .Interior.ColorIndex = 34 'light turquoise
Case 6: .Interior.ColorIndex = 6 'yellow
Case Is >= 5: .Interior.ColorIndex = 15 'gray 25%
Case Is >= 4: .Interior.ColorIndex = 5 'blue
Case Else: .Interior.ColorIndex = 3 'red
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)
 

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