Macro to change cell text color

J

James C

OBJECTIVE: I select a range of cells. I want a macro I can run tha
changes the color of the text based on 3 criteria:
(1) if a numeric value w/o an = sign or any mathematical operators
then RED
(2) if a forumla w/ an = sign, but no other operators, then GREEN
(3) if a formula w/ an = sign and operators, then BLUE

Can anyone post this?

Thanks.

- Ji
 
B

Bob Phillips

Jim,

Here's a shot

Dim cell As Range
Dim sFormula As String

For Each cell In Selection
If cell.HasFormula Then
sFormula =
"SUMPRODUCT(--(ISNUMBER(SEARCH({""+"",""-"",""~*"",""/"",""^""},""" &
cell.Formula & """))))"
If Evaluate(sFormula) > 0 Then
cell.Interior.ColorIndex = 5
Else
cell.Interior.ColorIndex = 10
End If
Else
If IsNumeric(cell.Value) Then
cell.Interior.ColorIndex = 3
End If
End If
Next cell

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Top