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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
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,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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