Hello,
this is driving me crazy and I really need some help.
It must be some basic stuff I just cannot grasp. Anyway:
I am using Excel 2010 on Windows 7
Typical situation of copying and pasting from one workbook to another.
I do a similar procedure in another bit of the macro and it works perfectly.
At this point, however it looks like it's copying but not pasting.
When I hover with the mouse I see that it gives me an Application-defined or object defined error (?!?)
Specifically I copy from
When I hover with the mouse I get (in the specific case)
LastRow=435 as it should be
LastRow=408 as it should be
col = 48 as it should be
BUT when I hover over Ws1.Cells(LastRow, col + 1 + LastCol) I get a Application-defined or object defined error
I realised it has something to do with the number of columns as the error appears if the value of column exceeds 256.
If for example I set LastCol = 100 then it works fine.
Why is it? Am I missing something?
Why does it work then when I copy and paste the range on the same workbook?
Any help would be much appreciated
Thanks
this is driving me crazy and I really need some help.
It must be some basic stuff I just cannot grasp. Anyway:
I am using Excel 2010 on Windows 7
Typical situation of copying and pasting from one workbook to another.
I do a similar procedure in another bit of the macro and it works perfectly.
At this point, however it looks like it's copying but not pasting.
When I hover with the mouse I see that it gives me an Application-defined or object defined error (?!?)
Specifically I copy from
Code:
Workbooks(datafilename2).Activate
Ws2.Select
LastCol = Ws2.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
LastRow = Ws2.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Ws2.Range(Ws2.Cells(1, 1), Ws2.Cells(LastRow, LastCol)).Copy
' and paste here
Workbooks(datafilename1).Activate
Ws1.Select
Ws1.Range(Ws1.Cells(1, col + 1), Ws1.Cells(LastRow, col + 1 + LastCol)).PasteSpecial xlPasteValues 'Application-defined or object defined error on the second .Cells
When I hover with the mouse I get (in the specific case)
LastRow=435 as it should be
LastRow=408 as it should be
col = 48 as it should be
BUT when I hover over Ws1.Cells(LastRow, col + 1 + LastCol) I get a Application-defined or object defined error
I realised it has something to do with the number of columns as the error appears if the value of column exceeds 256.
If for example I set LastCol = 100 then it works fine.
Why is it? Am I missing something?
Why does it work then when I copy and paste the range on the same workbook?
Code:
Workbooks(datafilename2).Activate
Ws2.Select
LastCol = Ws2.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
LastRow = Ws2.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Ws2.Range(Ws2.Cells(1, 1), Ws2.Cells(LastRow, LastCol)).Copy
Ws2.Range(Ws2.Cells(1, LastCol + 1), Ws2.Cells(LastRow, LastCol + 1 + LastCol)).PasteSpecial xlPasteValues 'works fine
Any help would be much appreciated
Thanks