Hi All,
I've been trying to make some ranges copy to another workbooks. Below code works perfect:
However I want to also copy-paste values from another sheet in the same workbook, so I extended the code:
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???
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???