|
-
July 27th, 2011, 05:57 PM
#1
Want to paste to xls file but doesn't work if Pasting To tab not default when opened.
Hi folks. Forgive the rookie.
I want to transfer one range from workbook A to a protected tab of workbook B.
The Problem: Spreadsheet B has multiple tabs. The tab it needs to be set to for the users' sake is '1'. The tab where the pasting is happening is called 'Transfer'. I want whatever the tab default is in B to not matter but it seems to matter. Shouldn't the answer just be Sheets(whatever tab you want to work on).select?
When I save workbook B with the 'Transfer' tab selected, close it, open the workbook A and then run the macro it works. B receives the necessary paste and is saved & closed.
When I save workbook B with the '1' tab selected, close it, open the workbook A and then run the macro I get "Error message: Run-time error '1004': Paste method of Worksheet class failed.
I have googled and looked on this site and I'm sure I've missed the obvious but I would love some direction in this please. Thank you for your kind attention.
David
Sub Copy_Employees_to_New_Month()
Range("AD4:AG172").Select
Selection.Copy
' I made the B spreadsheet determinable from a formula in the A spreadsheet so
' different users in different subdirectories could use it.
Workbooks.Open Filename:=Cells(25, "J")
' Make the current tab set to 'Transfer' before pasting.
Sheets("Transfer").Select
Sheets("Transfer").Unprotect Password:="secret"
' Specify where the pasting range is.
Range("AD4").Select
ActiveSheet.Paste (this is highlighted when I go to VB after the error)
Application.CutCopyMode = False
' Put the protection back on the Transfer tab.
Sheets('Transfer').Protect Password:="secret"
' Move the active tab to '1' before saving the Paste To spreadsheet.
Sheets("1").Select
ActiveWorkbook.Save
ActiveWorkbook.Close
' Move the cursor in the Copy From spreadsheet to cell J14.
Range("J14").Select
End Sub
What am I doing wrong?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|