Copy several ranges between workbooks

Przems

New Member
Joined
Sep 11, 2013
Messages
1
Hi All,

I've been trying to make some ranges copy to another workbooks. Below code works perfect:

Code:
Sub Copy_Range()
   Dim OriginWorkbook As Workbook, DataWorkbook1
   Dim StrPathOrigin As String, StrPathData1
   
   StrPathOrigin = "C:\Myfile.xls"
   StrPathData1 = "C:\MyData.xls"

   Workbooks.Open FileName:=StrPathOrigin
   Set OriginWorkbook = ActiveWorkbook
   Workbooks.Open FileName:=StrPathData1
   Set DataWorkbook1 = ActiveWorkbook
   
   DataWorkbook1.Sheets("CR - CDPIM").Range(Range("B4:BJ4"), Range("B4:BJ4").End(xlDown)).Copy
   OriginWorkbook.Sheets("OTC - CR").Range("A8").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub

However I want to also copy-paste values from another sheet in the same workbook, so I extended the code:

Code:
Sub Copy_Range()
   Dim OriginWorkbook As Workbook, DataWorkbook1
   Dim StrPathOrigin As String, StrPathData1
   
   StrPathOrigin = "C:\Myfile.xls"
   StrPathData1 = "C:\MyData.xls"

   Workbooks.Open FileName:=StrPathOrigin
   Set OriginWorkbook = ActiveWorkbook
   Workbooks.Open FileName:=StrPathData1
   Set DataWorkbook1 = ActiveWorkbook
   
   DataWorkbook1.Sheets("CR - CDPIM").Range(Range("B4:BJ4"), Range("B4:BJ4").End(xlDown)).Copy
    OriginWorkbook.Sheets("OTC - CR").Range("A8").PasteSpecial  Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

[B]   DataWorkbook1.Sheets("Lead time").Range(Range("B3:Z3"), Range("B3:Z3").End(xlDown)).Copy
   OriginWorkbook.Sheets("Leadtime - CR").Range("A6").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False[/B]
End Sub

Now You tell my why on the first of newly added lines I got a Run-time error '1004': Application-defined or object-defined error???
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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