Changing font colours

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I have the following code: -

Code:
For y = 2 To intRows
    With Sheets("KPI 5 - WBT")
        With .Range(.Cells(Sheets("KPI 5 - WBT").Cells(y, 6).Value, y), .Cells(110, y))
            With .Font
                .Color = Sheets("KPI 5 - WBT").Cells(y, 5).Value
                .TintAndShade = 0
            End With
        End With
    End With
Next y

where the value in

Code:
Sheets("KPI 5 - WBT").Cells(y, 5).Value

is either 0, -9571840 or -16776961, representing black, green and red respectively obtained by recording a macro.

I don't get an error but font in the cells don't change colour?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
The color numbers should work, I used this test code:

Code:
With ActiveCell
  .Value = "TEST"
  .Font.Color = -16776961
End With

But why don't you use the colorindex instead of color? For Black it's 1, for Green 14, for Red 3. Much simpler I think :-)

Try (untested):

Code:
Sub ff()

    For y = 2 To intRows
        With Sheets("KPI 5 - WBT")
            With .Range(.Cells(.Cells(y, 6).Value, y), .Cells(110, y))
                .Font.ColorIndex = .Parent.Cells(y, 5).Value
                .TintAndShade = 0
            End With
        End With
    Next

End Sub
 
Upvote 0
That worked wigi except that I had to change

Code:
.TintAndShade = 0

to

Code:
.Font.TintAndShade = 0
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top