A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How do I change the color of cells with a macro



 
 
Thread Tools Display Modes
  #1  
Old March 24th, 2010, 02:24 PM posted to microsoft.public.excel.misc
Mike DFR
external usenet poster
 
Posts: 27
Default How do I change the color of cells with a macro

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
  #2  
Old March 24th, 2010, 02:37 PM posted to microsoft.public.excel.misc
Don Guillett[_2_]
external usenet poster
 
Posts: 607
Default How do I change the color of cells with a macro


You don't give us much

select case range("a1").value
case0:mc=6
case2:mc=3
case else
end select
rows(1).interior.colorindex=mc


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mike DFR" wrote in message
...
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


  #3  
Old March 24th, 2010, 03:57 PM posted to microsoft.public.excel.misc
stumac
external usenet poster
 
Posts: 165
Default How do I change the color of cells with a macro

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

"Mike DFR" wrote:

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

  #4  
Old March 24th, 2010, 04:00 PM posted to microsoft.public.excel.misc
stumac
external usenet poster
 
Posts: 165
Default How do I change the color of cells with a macro

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

"stumac" wrote:

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

"Mike DFR" wrote:

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

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:03 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.