How do I change the color of cells with a macro

M

Mike DFR

I was using conditional formatting, but this only gives three options, I need 5
I am looking for a simple piece of code which says

If cell A1 is not zero color the row green, for example.

I have tried With range, If Else and Case

I get the first color, then it will not change
 
D

Don Guillett

You don't give us much

select case range("a1").value
case<>0:mc=6
case>2:mc=3
case else
end select
rows(1).interior.colorindex=mc
 
S

stumac

Hi Mike, you could try something like:

cv = Range("a1").Value
IC = Switch(cv > 10, vbRed, cv > 8, vbBlue, cv > 6, vbYellow, cv > 0, vbGreen)
Rows(1).Interior.Color = IC


Hth
Stu
 
S

stumac

Oops forgot to change the values to reflect your example - I am sure you will
get the idea though.
 

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