i'm trying to work with two sheets in two different workbooks. For some reason this code returns an error
Sub look()
Dim Source, Destination As Worksheet
Dim Range1_in_Source As Range
Dim Range1_in_Destination As Range
path = "" :file = "file name"
Set Source = Workbooks(2).Worksheets(1)
Set Destination= ThisWorkbook.Worksheets(1)
this assignment returns an object that is empty for Source when i inspect it using watch Destination however seems to work well -for now!
Set Range1_in_Source= Source.Range(Cells(2, 1), Cells(2, 1).End(xlDown))
Set Range1_in_Destination = Destination.Range(Cells(5, 1), Cells(5, 1).End(xlDown))
for some reason the last line gives a runtime 1004 error (method 'Range' of object '_global' failed) And the cells are referring to the Source sheet not Destination.
what is wrong in my code
Source
asVariant
. The line should be:Dim Source As Worksheet, Destination As Worksheet
.Workbooks(2)
is not a good idea it might as well be the same as 'ThisWorkbook'.xlDown
is also a bad idea. AndCells
are not qualified. Try posting the full code fromSub
toSub
. There is an edit button below your post. – VBasic2008