PDA

View Full Version : EXCEL if statement to test color?


joeorez
11-06-2003, 08:34 AM
Hi,

I recently received a list of claims that was color-coded. I am color-challenged. I know EXCEL has a capability where you can say something like, "IF CELL A1=AUTOMOBILE then format the cell in red, " but does it have the capability to say something like "IF CELL A1 is formatted in red, then it is AUTOMOBILE?"

Jay Oliver
11-06-2003, 09:17 AM
Joe,

This code tests if the cell interior color is red.

If Selection.Interior.ColorIndex = 3 Then MsgBox "Automobile"

The three is the index for red. If you would like a list with the colors and their applicable index numbers, reply here and I will send you a PM.

Jay

Bama Gambler
11-06-2003, 09:43 AM
Add the following function to a module in your workbook (or to your personal workbook):

Function CELLCOLORINDEX(Cell) As Long
' Returns a number that corresponds to a cell''s background color
CELLCOLORINDEX = Cell(1).Interior.ColorIndex
End Function

Now go buy the book Excel 2002 Power Programming with VBA by John Walkenbach. I also recomend purchasing PUP5 and source code.