Change Shape Fill and Font colour based on cell value

EdRooney

New Member
Joined
Jun 29, 2012
Messages
14
Hi everyone.
I have some VBA Code that works well to change the colour of a shape, dependent upon a cell value.
Some of the shape colour choices do not work well with white font, eg a bright yellow shape, but this is the colour of choice!

Here is my code and I wondered if someone could please tell me the add in code I need to change the font colour at the same time as changing the shape colour?

Thank you in advance

VBA Code:
Private Sub Worksheet_Calculate()

    Dim rngC As Range
    Dim shp As Shape
   
    For Each rngC In Me.Range("R8:R39")
   
        Set shp = Me.Shapes("tbox" & rngC.Row - 7)
       
        shp.Fill.ForeColor.RGB = RGB(166, 166, 166)
       
        If Sheet14.Cells(rngC.Row, 18) = "Chaos" Then
        shp.Fill.ForeColor.RGB = RGB(255, 0, 0)
       
        ElseIf Sheet14.Cells(rngC.Row, 18) = "Reactive" Then
        shp.Fill.ForeColor.RGB = RGB(237, 125, 49)
       
        ElseIf Sheet14.Cells(rngC.Row, 18) = "Control" Then
        shp.Fill.ForeColor.RGB = RGB(84, 130, 53)
       
        ElseIf Sheet14.Cells(rngC.Row, 18) = "Best Practice" Then
        shp.Fill.ForeColor.RGB = RGB(68, 114, 196)
       
        ElseIf Sheet14.Cells(rngC.Row, 18) = "Excellence" Then
        shp.Fill.ForeColor.RGB = RGB(255, 255, 0)

    End If
   
    Next rngC

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,856
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
         shp.TextFrame.Characters.Font.Color = 1
 
Solution

EdRooney

New Member
Joined
Jun 29, 2012
Messages
14
Perfect, thank you. That has worked.
I was using With and End With ! Doh!
I am very grateful for your help
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,856
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,122
Messages
5,640,242
Members
417,131
Latest member
Seanr19871

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
Top