Great title. Concise but long.
I have a VB script to move data from a particular tab on workbook A to the same named tab on workbook B. The macro button is on A's tab being copied.
The problem is that the default tab of workbook B is not where the pasting is going. The users need the workbooks to always be on another tab when they open it up.
I can make this macro work if I previously save B on the tab I need the data to go. If I save B on the user's default tab and get out and then run the macro in A I get "Run-time error '1004' PasteSpecial method of Range class failed". The macro stops working while on the target tab of Workbook B in cell AD4.
Also, I determine where the paste is going based on a formula in Workbook A's macro button tab. That works because I'm getting to the right Workbook to paste.
What am I missing in my VB so that it won't conk out when it tries to go to the correct tab to paste in Workbook B?
I would appreciate anyone's kind attention to this problem. I am very much a rookie at this but it would make a lot of users happy if this could work.
Best regards,
David
My code is as follows:
Sub Copy_Employees_To_Following_Month()
'
' Button13_Click Macro
' Macro recorded 07/21/2011 by davem
'
Range("AD4:AG172").Select
Selection.Copy
Workbooks.Open Filename:=Cells(25, "J")
Sheets("Transfer").Select
Sheets("Transfer").Unprotect Password:="secret"
Range("AD4").Select
Selection.PasteSpecial
Application.CutCopyMode = False
Sheets("Transfer").Protect Password:="secret"
Sheets("1").Select
ActiveWorkbook.Save
ActiveWindow.Close
ActiveWindow.LargeScroll ToRight:=-2
ActiveWindow.LargeScroll Down:=-6
Range("J14").Select
End Sub
I have a VB script to move data from a particular tab on workbook A to the same named tab on workbook B. The macro button is on A's tab being copied.
The problem is that the default tab of workbook B is not where the pasting is going. The users need the workbooks to always be on another tab when they open it up.
I can make this macro work if I previously save B on the tab I need the data to go. If I save B on the user's default tab and get out and then run the macro in A I get "Run-time error '1004' PasteSpecial method of Range class failed". The macro stops working while on the target tab of Workbook B in cell AD4.
Also, I determine where the paste is going based on a formula in Workbook A's macro button tab. That works because I'm getting to the right Workbook to paste.
What am I missing in my VB so that it won't conk out when it tries to go to the correct tab to paste in Workbook B?
I would appreciate anyone's kind attention to this problem. I am very much a rookie at this but it would make a lot of users happy if this could work.
Best regards,
David
My code is as follows:
Sub Copy_Employees_To_Following_Month()
'
' Button13_Click Macro
' Macro recorded 07/21/2011 by davem
'
Range("AD4:AG172").Select
Selection.Copy
Workbooks.Open Filename:=Cells(25, "J")
Sheets("Transfer").Select
Sheets("Transfer").Unprotect Password:="secret"
Range("AD4").Select
Selection.PasteSpecial
Application.CutCopyMode = False
Sheets("Transfer").Protect Password:="secret"
Sheets("1").Select
ActiveWorkbook.Save
ActiveWindow.Close
ActiveWindow.LargeScroll ToRight:=-2
ActiveWindow.LargeScroll Down:=-6
Range("J14").Select
End Sub
Last edited: