Shape name changes with worksheet copy

OfficeUser

Well-known Member
Joined
Feb 4, 2010
Messages
544
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a worksheet where shape changes color when a command button is clicked.
Code:
Private Sub lblChem_Click()
ActiveSheet.Unprotect Password:="password"
    If Shapes("Oval 1").Fill.ForeColor.SchemeColor = 10 Then 'Red
    Shapes("Oval 1").Fill.ForeColor.SchemeColor = 11
        Range("AW10:BA10,S10:W10").Select
        Selection.Locked = False
Range("AC5").Select
Else
    If Shapes("Oval 1").Fill.ForeColor.SchemeColor = 11 Then 'Green
    Shapes("Oval 1").Fill.ForeColor.SchemeColor = 10
        Range("AW10:BA10,S10:W10").Select
        Selection.Locked = True
Range("AC5").Select
End If
End If
ActiveSheet.Protect Password:="password"
End Sub
It works fine as-is. If I copy the worksheet then the shape name changes to something like "Oval16" or "Oval 4" thus causing my code to error.

Is there a way to keep this from happening? I don't have this issue with my command buttons so I am not seeing the difference here. Suggestions? Thanks.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I can't reproduce that behaviour in Excel 2003. If I copy a worksheet to another workbook, shapes retain their original names.
 
Upvote 0
Thats odd. I thought maybe I had to declare it globally or something.
 
Upvote 0
Wrong wording. I thought maybe there was a way to solidify the shapes name in vba.
 
Upvote 0
It will not change the fill color to green once I change it to Shapes(1). However I do not get an error suing Shapes(1).
 
Upvote 0
I could not figure it out. I have since swapped the oval for a label which does the same thing and it works as intended. Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,334
Members
452,907
Latest member
Roland Deschain

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