Code to change color of shapes

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,835
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
Hi All
Having a moment.
I modified this code from Snowblizz....but it won't work.
Doesn't error out just runs, with no color changes.
Basically, the comment in cell "F" makes the color of the shape ( Oval) change

I'm missing something simple and it's finally got into my head.....
Any assistance appreciated
Code:
Sub CLChange()
'SnowBlizz
Dim i As Integer, cell As Variant, lr As Long
Dim colourNr As Integer
Application.ScreenUpdating = False
On Error Resume Next
Sheets("Sheet1").Activate
For i = 10 To 32
    Select Case Range("F" & i).Value
    Case "On Target"
            colourNr = 3
    Case "May Need Attention"
            colourNr = 47
    Case "Urgent attention Reqd"
            colourNr = 10
End Select
        With ActiveSheet.Shapes(Range("F" & i).Value)
            .ShapeRange.Fill.ForeColor.SchemeColor = colourNr
        End With
Next i
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi Michael,

It's failing at the following part:

Code:
With ActiveSheet.Shapes(Range("F" & i).Value)
            .ShapeRange.Fill.ForeColor.SchemeColor = colourNr
        End With

Assuming the the relevant shape name is the same as the value in the cell, try this:

Code:
ActiveSheet.Shapes(Range("F" & i).Value).Fill.ForeColor.SchemeColor = colourNr

HTH

Robert
 
Upvote 0
Hi Robert
Yep, that fixed it.
I also had a couple of shapes that were formatted as no fill rather than Automatic...which caused them not to work as well
Thanks for the assist.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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