ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to change cell text color (https://www.excelbanter.com/excel-discussion-misc-queries/40146-macro-change-cell-text-color.html)

James C

Macro to change cell text color
 

OBJECTIVE: I select a range of cells. I want a macro I can run that
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.

- Jim


--
James C
------------------------------------------------------------------------
James C's Profile: http://www.excelforum.com/member.php...o&userid=12114
View this thread: http://www.excelforum.com/showthread...hreadid=395347


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)


"James C" wrote in
message ...

OBJECTIVE: I select a range of cells. I want a macro I can run that
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.

- Jim


--
James C
------------------------------------------------------------------------
James C's Profile:

http://www.excelforum.com/member.php...o&userid=12114
View this thread: http://www.excelforum.com/showthread...hreadid=395347





All times are GMT +1. The time now is 09:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com