Code to change color of shapes

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,405
Office Version
  1. 2016
  2. 2013
  3. 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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
4,744
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
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,405
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,639
Messages
5,660,028
Members
418,543
Latest member
alreadybeen23

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