Copy & Paste Macro (Buttons) into new worksheet

poexaa2

New Member
Joined
Sep 8, 2011
Messages
7
Can anyone help please.

Having read some of the VBA queries on here I'm embarrassed to ask but am still new to this VBA thing so...

I have recorded some very simple 1 line Macros with buttons assigned to automate navigation around a worksheet to different ranges. Typical code=

Range("DashboardSum").Select

and that's it!!

This does the job in the worksheet I am in. I then want to copy the entire contents of the worksheet and paste into another for the next months data. All fine, however when I hit a macro button in the new worksheet I get the 'Run-time error '1004': Select method of Range class failed' message. I am not pasting into a new file, just a new sheet that I have inserted.

I have looked around different forums for related threads but they all appear to be way too complicated for what must surely require a simple bit of editing.

Can someone with a bigger brain than I please help.

thanks

poexaa2
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Something like this should work

Code:
Range("DashboardSum").Copy Destination:=Sheets("Sheet2").Range("A1")
 
Upvote 0
Thx very much VoG

Bear with me! So I edit my existing code to match your suggestion. But then it does not work in the original spreadsheet, even before I have attempted to copy and paste anything. Why is the element of the code .Range ("A1") necessary? What am I missing here???

Really sorry, I obviously need spoon-feeding.

P
 
Upvote 0
Can you post the code that you have and explain in words what you are trying to do.
 
Upvote 0
Can you post the code that you have and explain in words what you are trying to do.

Thx

This is the full code:-

Sub GoToDashboard()
'
' GoToDashboard Macro
' Macro recorded 05/09/2011 by Cliff
'
' Keyboard Shortcut: Ctrl+d
'

Range("DashboardSum").Select
End Sub

And that's it. All I am trying to do is move around a spreadsheet where the client wants various linked schedules (that I have Rangenamed) all on one worksheet for each period. The macro's are all the same (EXCEPT FOR THE RANGE NAME) as above. The associated buttons been copied and pasted above each schedule on the worksheet so that you can move from one schedule to another without having to go hunting for their location. At the start of a new period a new worksheet is inserted into the file and we then want to copy and paste the entire worksheet from the previous period onto the new one. The macro buttons do not work in the new spreadsheet that has been pasted and I get the error message described above.

Hope this helps.

Thx again.

P
 
Upvote 0
That will (as you've discovered) generate an error if the worksheet with that range is not active. Try

Code:
Sub GoToDashboard()
'
' GoToDashboard Macro
' Macro recorded 05/09/2011 by Cliff
'
' Keyboard Shortcut: Ctrl+d
'

Application.Goto Range("DashboardSum"), True
End Sub
 
Upvote 0
That will (as you've discovered) generate an error if the worksheet with that range is not active. Try

Code:
Sub GoToDashboard()
'
' GoToDashboard Macro
' Macro recorded 05/09/2011 by Cliff
'
' Keyboard Shortcut: Ctrl+d
'
 
Application.Goto Range("DashboardSum"), True
End Sub


Fantastic!!, thank you. Works wonderfully.

Just joined Mr Excel, hopefully I will be able to help someone else at some point. Thanks again, much appreciated.
 
Upvote 0
That will (as you've discovered) generate an error if the worksheet with that range is not active. Try

Code:
Sub GoToDashboard()
'
' GoToDashboard Macro
' Macro recorded 05/09/2011 by Cliff
'
' Keyboard Shortcut: Ctrl+d
'
 
Application.Goto Range("DashboardSum"), True
End Sub


Thanks v.much!! Fantastic, works wonderfully. Hopefully, I will be able to assist someone in the future with an Excel query. Much appreciated.
 
Upvote 0
Thanks v.much. Fantastic, works wonderfully. Hopefully I will be able to assist someone with a query in the future. Much appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,461
Members
452,915
Latest member
hannnahheileen

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