need conditional format for 6 conditions

franko

Board Regular
Joined
Jul 7, 2005
Messages
77
Does anybody know how to have more than 3 conditions
on one cell for instance I need 6 different colour conditions

so if conditions:

1 ) Cell Value in A1 = "C" colour needs to be in red
2 ) Cell Value in A1 = "H" colour needs to be in yellow
3 ) Cell Value in A1 = "N" colour needs to be in green
4 ) Cell Value in A1 = "S" colour needs to be in blue
5 ) Cell Value in A1 = "L" colour needs to be in black
6 ) Cell Value in A1 = "D" colour needs to be in gray

unfortunately I have discovered that there is a limitation of 3 conditions
so how can I add more conditions ????


any help is highly appreciated :)

thanks
franko
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
you would have to do it with code...
are you only checking cell A1 and then coloring cell A1?

if so something like this possibly


Code:
If Range("A1").value="C" then Range("A1").interior.color=vbRed
etc, etc....

let me know if that'll work or if you need more help
 
Upvote 0
For more than 3 conditions, you have to use a macro.

I believe this should work for you.

<font face=Tahoma><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)

<SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> Finish
Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN>

<SPAN style="color:#007F00">'if more than 1 cell is changed or changed cell is not A1, exit macro</SPAN>
<SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Or</SPAN> Target.Address(0, 0) <> "A1" <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> Finish

<SPAN style="color:#007F00">'otherwise, run following code to check value of A1 and _
change colors</SPAN>
<SPAN style="color:#00007F">Select</SPAN> <SPAN style="color:#00007F">Case</SPAN> Target.Value
    <SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Is</SPAN> = "C"
        Target.Interior.ColorIndex = 3 <SPAN style="color:#007F00">'red</SPAN>
    <SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Is</SPAN> = "H"
        Target.Interior.ColorIndex = 6 <SPAN style="color:#007F00">'yellow</SPAN>
    <SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Is</SPAN> = "N"
        Target.Interior.ColorIndex = 4 <SPAN style="color:#007F00">'green</SPAN>
    <SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Is</SPAN> = "S"
        Target.Interior.ColorIndex = 5 <SPAN style="color:#007F00">'blue</SPAN>
    <SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Is</SPAN> = "L"
        Target.Interior.ColorIndex = 1 <SPAN style="color:#007F00">'black</SPAN>
    <SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Is</SPAN> = "D"
        Target.Interior.ColorIndex = 15 <SPAN style="color:#007F00">'gray</SPAN>
    <SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Else</SPAN>
        Target.Interior.ColorIndex = -4142 <SPAN style="color:#007F00">'no color</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Select</SPAN>

Finish: Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN>

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

You have to put the code in the correct module, though. Right-click the sheet tab and select View Code. Paste this code into the window that appears. Then this code should run whenever a change is made on that sheet.

NOTE: This code will NOT run if the cells are being changed by formulas. You need a different macro for that.
 
Upvote 0
Hi ,

does your macro code work for a whole worksheet
as it is used on severel columns in differrent rows and cells
so would be nice if it would recognise any value in several cells on any columns....

how does the macro start with usually it starts with
sub .. () didn`t see that on your posted code sorry for this poor question

regards
franko
 
Upvote 0
Hi ,

your solution sounds good
could you give me an example of minimum 4 conditions in one formula
and I'll catch up hopefully to customize it for 6 conditions
even I will need to distribute this formula in any column needed on my worksheet


thanks
franko
 
Upvote 0
Kristy posted the whole code for you...if you need anything else then post back...

ps if you need it for the whole sheet and not just A1 (let us know if not the whole sheet but maybe certain columns)....then change

If Target.Count > 1 Or Target.Address(0, 0) <> "A1" Then GoTo Finish

to

If Target.Count > 1 Then GoTo Finish
 
Upvote 0
In the code that Kristy posted, change this line

If Target.Count > 1 Or Target.Address(0, 0) <> "A1" Then GoTo Finish

to this line

If Target.Count > 1 Then GoTo Finish

If you need to cover the possibility of changinf more than 1 cell at a time, then post back.

The macro is not run by you directly, but rather fires each time you change a cell.
 
Upvote 0
Hi I tried the code below doesn't work
BTW need to look at whole sheet ....

and running XLS 2000 ...

thanks
franko



Sub Macro1()
'
' Macro1 Macro
' Macro recorded 26/08/2005

On Error GoTo Finish
Application.EnableEvents = False

If Target.Count > 1 Then GoTo Finish

Select Case Target.Value
Case Is = "C"
Target.Interior.ColorIndex = 3 'red
Case Is = "H"
Target.Interior.ColorIndex = 6 'yellow
Case Is = "N"
Target.Interior.ColorIndex = 4 'green
Case Is = "S"
Target.Interior.ColorIndex = 5 'blue
Case Is = "L"
Target.Interior.ColorIndex = 1 'black
Case Is = "D"
Target.Interior.ColorIndex = 15 'gray
Case Else
Target.Interior.ColorIndex = -4142 'no color
End Select

Finish: Application.EnableEvents = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,969
Messages
6,175,680
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top