Copy Sheet maintaining Macros

pebusto

New Member
Joined
Jan 13, 2014
Messages
3
Hi,

I've created a sheet containing some macros (see below as an example).
The issue is that when I create a copy of this sheet in the same workbook, all the macros references get lost and i get the Run-time error '1004': The item with the specified name wasn't found.
Is there anyway to fix this issue?

Many thanks in advance,
Pablo


Sub OptionButton5_Click()

'
' OptionButton5_Click Macro
'

'
ActiveSheet.Shapes.Range(Array("TextBox 22")).Select
ActiveSheet.Shapes.Range(Array("TextBox 22", "TextBox 20")).Select
ActiveSheet.Shapes.Range(Array("TextBox 22", "TextBox 20", "TextBox 68")). _
Select
ActiveSheet.Shapes.Range(Array("TextBox 22", "TextBox 20", "TextBox 68", _
"TextBox 63")).Select
ActiveSheet.Shapes.Range(Array("TextBox 22", "TextBox 20", "TextBox 68", _
"TextBox 63", "TextBox 1")).Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
.Solid
End With
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
.Solid
End With
ActiveCell.Offset(2, -2).Range("A1:S3").Select
ActiveSheet.Shapes.Range(Array("Rectangle 2")).Select
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi pebusto,
Because this is running on the active sheet, have you tried something like;
Code:
 Sheets("Sheet1").select
,at the beginning of the code which will tell the macro which sheet you want it to be run on?

HeyYouYesYouNoNotYouYou
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,101
Members
449,205
Latest member
ralemanygarcia

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