MrExcel Publishing
Your One Stop for Excel Tips & Solutions

changing cell colors with code


Posted by Jeffrey Slavin on August 23, 2001 11:03 AM

i am looking to write code that looks somewhat like the following:

if cellA == cellB then cellB should have the color of blue.

basically i want to be able to change the color of the text or background of a cell if something is true (ie: two cells are equal in this case).
is this possible?

thanks
please email me, JSlavinNU@aol.com


Posted by Mindy on August 23, 2001 11:18 AM

Hi Jeffrey

Yes, it can be done.

Example:
with worksheets(1)
if .range("A1").value = .range("B1") then .range("B1").interior.color = RGB(204,255,255)

end with


204, 255,255 -- light blue
153, 204, 255 -- blue
255, 255, 255 -- white
255,255, 204 -- yellow
153,204,255 -- green

hope this help

Mindy

Posted by Wit on August 27, 2001 1:37 AM

use Format -> Condition

If you want to compare a1 and b1
in Cell B1 use Format ->Condition
Formula is -> =b1=a1
format that you want
After that if you have many rows you want to compare, using format painter.