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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
How about
VBA Code:
         shp.TextFrame.Characters.Font.Color = 1
 
Upvote 0
Solution
Perfect, thank you. That has worked.
I was using With and End With ! Doh!
I am very grateful for your help
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,221
Messages
6,123,701
Members
449,117
Latest member
Aaagu

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