ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change the font color based on the value of the cell (https://www.excelbanter.com/excel-programming/423655-change-font-color-based-value-cell.html)

robin

Change the font color based on the value of the cell
 
How do I create a macro or program to change the font color of a particular
cell based on the value of the cell, e.g. 1 3 5 7, change the font color to
red, if 0, 00 change font color to green and bold, thanks in advance

JLGWhiz[_2_]

Change the font color based on the value of the cell
 
If Range("A1").Value = SomeValue Then
Range("A1").Font.ColorIndex = 3 'ColorIndex 3 is Red
End If


"Robin" wrote in message
...
How do I create a macro or program to change the font color of a
particular
cell based on the value of the cell, e.g. 1 3 5 7, change the font color
to
red, if 0, 00 change font color to green and bold, thanks in advance




JLGWhiz[_2_]

Change the font color based on the value of the cell
 
For more than one value:

If Range("A1").Value = SomeValue Then
Range("A1").Font.ColorIndex = 3
ElseIf Range("A1").Value = AnotherValue Then
Range("A1").Font.ColorIndex = 12
End If

Or you could use select case if you have several values to check.



"Robin" wrote in message
...
How do I create a macro or program to change the font color of a
particular
cell based on the value of the cell, e.g. 1 3 5 7, change the font color
to
red, if 0, 00 change font color to green and bold, thanks in advance




robin

Change the font color based on the value of the cell
 
what if i wanted to include the values 1 3 5 7 how do i code the SomeValue

"JLGWhiz" wrote:

If Range("A1").Value = SomeValue Then
Range("A1").Font.ColorIndex = 3 'ColorIndex 3 is Red
End If


"Robin" wrote in message
...
How do I create a macro or program to change the font color of a
particular
cell based on the value of the cell, e.g. 1 3 5 7, change the font color
to
red, if 0, 00 change font color to green and bold, thanks in advance





Rick Rothstein

Change the font color based on the value of the cell
 
Doing a Roulette worksheet, huh? <g

I think Conditional Formatting would be the best to use. Select your
"particular cell" (I'll assume you selected A1 for this example...change the
A1 in the formulas below to whatever the address is for the actual
"particular cell" you selected) and then click Format/Conditional Formatting
from the menu bar. On the dialog box that comes up, select "Formula Is" from
the first drop down and then put this formula in the empty field to its
right...

=AND(MOD(A1,2)=1,A1<"")

Then click the Format button, select the Patterns tab and pick the red color
you want. If you pick a dark red color, then you might want to click the
Font tab and make the Font color white for readability. When done, click OK
to go back to the first dialog box. Next, click the Add button and select
"Formula Is" for Condition 2 (the condition you just Add'ed) and put this
formula in the empty field to its right...

=AND(OR(A1="0",A1="00"),A1<"")
--
Rick (MVP - Excel)


"Robin" wrote in message
...
How do I create a macro or program to change the font color of a
particular
cell based on the value of the cell, e.g. 1 3 5 7, change the font color
to
red, if 0, 00 change font color to green and bold, thanks in advance



curlydave

Change the font color based on the value of the cell
 
On Feb 8, 2:00*pm, Robin wrote:
what if i wanted to include the values 1 3 5 7 how do i code the SomeValue

The somevalue is there for you to hard code, replace somevalue with a
value, replace another value with another value

robin

Change the font color based on the value of the cell
 
yes roulette worksheet =) thanks

"Rick Rothstein" wrote:

Doing a Roulette worksheet, huh? <g

I think Conditional Formatting would be the best to use. Select your
"particular cell" (I'll assume you selected A1 for this example...change the
A1 in the formulas below to whatever the address is for the actual
"particular cell" you selected) and then click Format/Conditional Formatting
from the menu bar. On the dialog box that comes up, select "Formula Is" from
the first drop down and then put this formula in the empty field to its
right...

=AND(MOD(A1,2)=1,A1<"")

Then click the Format button, select the Patterns tab and pick the red color
you want. If you pick a dark red color, then you might want to click the
Font tab and make the Font color white for readability. When done, click OK
to go back to the first dialog box. Next, click the Add button and select
"Formula Is" for Condition 2 (the condition you just Add'ed) and put this
formula in the empty field to its right...

=AND(OR(A1="0",A1="00"),A1<"")
--
Rick (MVP - Excel)


"Robin" wrote in message
...
How do I create a macro or program to change the font color of a
particular
cell based on the value of the cell, e.g. 1 3 5 7, change the font color
to
red, if 0, 00 change font color to green and bold, thanks in advance




muddan madhu

Change the font color based on the value of the cell
 
may be this one

assumed your value is in Cell A1

Private Sub worksheet_change(ByVal target As Range)
target = Range("A1")
For a = 1 To 7 Step 2
If target = a Then
target.Font.ColorIndex = 3
Exit Sub
Else
target.Font.ColorIndex = 0
End If
Next
End Sub


On Feb 9, 1:33*am, Robin wrote:
How do I create a macro or program to change the font color of a particular
cell based on the value of the cell, e.g. 1 3 5 7, change the font color to
red, if 0, 00 change font color to green and bold, thanks in advance



Rick Rothstein

Change the font color based on the value of the cell
 
I gave you some bad advice... I gave you how to change the fill color, but I
see you want to change the font color. Instead of choosing Patterns, select
the Font tab and just choose the color you want your font to be. All other
instructions are as I posted them.

--
Rick (MVP - Excel)


"Robin" wrote in message
...
yes roulette worksheet =) thanks

"Rick Rothstein" wrote:

Doing a Roulette worksheet, huh? <g

I think Conditional Formatting would be the best to use. Select your
"particular cell" (I'll assume you selected A1 for this example...change
the
A1 in the formulas below to whatever the address is for the actual
"particular cell" you selected) and then click Format/Conditional
Formatting
from the menu bar. On the dialog box that comes up, select "Formula Is"
from
the first drop down and then put this formula in the empty field to its
right...

=AND(MOD(A1,2)=1,A1<"")

Then click the Format button, select the Patterns tab and pick the red
color
you want. If you pick a dark red color, then you might want to click the
Font tab and make the Font color white for readability. When done, click
OK
to go back to the first dialog box. Next, click the Add button and select
"Formula Is" for Condition 2 (the condition you just Add'ed) and put this
formula in the empty field to its right...

=AND(OR(A1="0",A1="00"),A1<"")
--
Rick (MVP - Excel)


"Robin" wrote in message
...
How do I create a macro or program to change the font color of a
particular
cell based on the value of the cell, e.g. 1 3 5 7, change the font
color
to
red, if 0, 00 change font color to green and bold, thanks in advance





Rick Rothstein

Change the font color based on the value of the cell
 
If you really want VB code instead of the Conditional Formatting I
recommended earlier, then use this worksheet event code instead (where you
would change the A1 to the cell address of the "particular cell" you want to
have this functionality)...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0,0) < "A1" Then Exit Sub
If Target.Value Mod 2 = 1 Then
Target.Font.ColorIndex = 3
ElseIf Target.Value = "0" Or Target = "00" Then
Target.Font.ColorIndex = 4
Else
Target.Font.ColorIndex = 0
End If
End Sub

--
Rick (MVP - Excel)


"Robin" wrote in message
...
How do I create a macro or program to change the font color of a
particular
cell based on the value of the cell, e.g. 1 3 5 7, change the font color
to
red, if 0, 00 change font color to green and bold, thanks in advance




All times are GMT +1. The time now is 06:35 PM.

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