runtime error 1004 paste method of worksheet class failed

Yeoman.jeremy

Board Regular
Joined
Apr 4, 2011
Messages
90
Hi there.
Basically, i'm trying to copy and paste certain cells from one workbook, to another, I've looked up many other threads but couldn't find anything specifically that can help me.

Basically what happens in this excel workbook, is I have a Command button that will call this macro, to transfer certain data from the current workbook into a blank version of the workbook.

Here is my coding so far


Sub DuplicateComplex_mcr()
Dim wbk As Workbook

strFirstFile = "c:\Documents and settings\Jan\Desktop\On The Job Sheet"

Set wbk = ThisWorkbook
With wbk.Sheets("Job Sheet")
.Range("B2").Copy
End With

Set wbk = Workbooks.Open(strFirstFile)
With wbk.Sheets("Job Sheet")
Range("b2").Select
ActiveSheet.Paste

End With

End Sub



Any help would be very much appreciated
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
On The Job Sheet.xls
or something like that. I think that's the problem


The coding actually opens the other workbook fine.
When i didnt have the "Range("b2").Select" included, it pasted perfectly fine into the other workbook, in the correct sheet, except it only pasted into cell A1
 
Upvote 0
try this

Code:
Set wbk = Workbooks.Open(strFirstFile)
With wbk.Sheets("Job Sheet")
     .Activate
     Range("b2").Select
     ActiveSheet.Paste
    
End With
 
Upvote 0
Try this.
Code:
Sub DuplicateComplex_mcr()
Dim wbk1 As Workbook
Dim wbk2 As Workbook

strFirstFile = "c:\Documents and settings\Jan\Desktop\On The Job Sheet"

Set wbk1 = ThisWorkbook
 
Set wbk2 = Workbooks.Open(strFirstFile)

wbk1.Sheets("Job Sheet").Range("B2").Copy

wbk2.Sheets("Job Sheet").Range("B2").PasteSpecial xlPasteValues

End Sub
 
Upvote 0
Try this.
Code:
Sub DuplicateComplex_mcr()
Dim wbk1 As Workbook
Dim wbk2 As Workbook

strFirstFile = "c:\Documents and settings\Jan\Desktop\On The Job Sheet"

Set wbk1 = ThisWorkbook
 
Set wbk2 = Workbooks.Open(strFirstFile)

wbk1.Sheets("Job Sheet").Range("B2").Copy

wbk2.Sheets("Job Sheet").Range("B2").PasteSpecial xlPasteValues

End Sub


PERFECT!
thank you very much, saved me many a headache! :3
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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