Gene Augustin said:
MAC Powerbook G4, OS 10.5.8
Office 2004, Excel 2004 Version 11.5.6
I would like to do:
=If(cell A7 colorindex=7, "Do something", "Do something else")
Don't know how to format the if "logical test" to use the color of the cell
Functions don't have access to formatting directly.
You can do this with a User Defined Function, but there are several
caveats...
First, put this macro in a regular code module (Option+F11 to enter the
VBE, choose Insert/Module, then type or paste):
Public Function MyColor() As Long
If TypeName(Application.Caller) = "Range" Then
MyColor = Application.Caller.Interior.ColorIndex
End If
End Function
(Option F11 to return to XL).
Then use
=IF(MyColor()=7,"Do something", "Do something else")
Caveat 1: Changing format doesn't trigger a calculation event, so
changing cell interior colors won't result in a change in the value. You
can cause the sheet to recalculate by typing CMD=
Caveat 2: Cells are only recalculated if they contain a volatile
function or if their precedents change. To make the function above
volatile, use something like:
=IF(MyColor=7+RAND()*0,"Do something", "Do something else")
Now that function will recalculate if you type CMD=