select method of range class failed

SSPoulin23

New Member
Joined
Nov 21, 2014
Messages
44
I cannot for the life of me get this to stop happening. I have a button on a summary page that, once clicked, unhides a sheet makes a copy, and would reference the information on the summary sheet onto the newly copied sheet. there will be other functions as well, but I cant get the "select method of range class failed" to go away! ive used this code before in another workbook but am having trouble here. any help would be great appreciated. thank you!

Private Sub CommandButton1_Click()

' Unhide Sheets
Sheets("Summary").Select
Sheets("Template").Visible = True

' Create Duplicate Sheets
Sheets("Template").Select
Sheets("Template").Copy Before:=Sheets(1)
' ReassignCellRefs
Sheets("Template (2)").Select
Range("C11").Select
ActiveCell.FormulaR1C1 = "='Summary'!R[-2]C"

End sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Typically, command buttons are given different numbers, so it is rare that you would have two with the exact same name. I know you cannot have that on the same sheet, but I never really tried across different sheets to see if it allowed that.

Best practices would seem to dictate using different names to avoid confusion.
 
Last edited:
Upvote 0
sorry for not being clear - they ARE on separate sheets.
Even so, I would still recommend using different names.
 
Upvote 0
You usually want to change it to match the actual name of the Command Button (so it makes sense).

I did some initial testing, and it looks like if you create button on different sheet it may re-use the same command button name.
So, if you do that, you may actually want the code on the Sheet module, to avoid confusion.

As you have seen, things can sometimes get a little flaky when working across different sheets from within the Sheet modules. If you do so, you may want to qualify all range references by prefix them with the sheet name, and see if that resolves the issues you were having.

Or, you can create code in a General Module to do what you want, and then just have your Command Button click code in the Sheet module call that procedure.
 
Upvote 0

Forum statistics

Threads
1,216,438
Messages
6,130,632
Members
449,584
Latest member
c_clark

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