• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

help with copy range

Pilot5000

New Member
I got the sheet (sheet2)with certain data, I also have the following code that suppose to copy the data from sheet2 to sheet1 at column A 3 rows after the last row with data , the code was working fine as long as I place my data in sheet2 starting column E to t he right , but I am trying to do the same thing but the data will start from column A to the right , when I tried that I keep getting the message "run time error 104 copy area and paste area are not the same size" any idea why and suggestion how to fix that ?????? my code is
Code:
Sub COPY_1()

Dim i As Integer

Application.ScreenUpdating = False
Worksheets("Sheet2").Select

For i = 5 To 23 Step 2
  If i <> 17 Then Range(Cells(2, i), Cells(2, i).End(xlDown).Offset(, 1)).Copy Destination:=Worksheets("sheet1").Range("A" & Rows.Count).End(xlUp).Offset(3)
Next
Application.ScreenUpdating = True
End Sub
 

Attachments

  • datafrom server 4weeks.xls
    83 KB · Views: 0
Enter Debug Mode when the error is prompted and check the copied range. The error you're getting sounds to me like the range is empty.
 
hi iferror , I have done the Debug mode as you suggested , and the line that come up in the code as problematic is
"Range(Cells(2, i), Cells(2, i).End(xlDown).Offset(, 1)).Copy Destination:=Worksheets("sheet1").Range("A" & Rows.Count).End(xlUp).Offset(3)"
and the message "run time error 104 copy area and paste area are not the same size". moreover , I forgot to mentioned that the information is being copied to the appropriate location as indicated in the macro but still I got that error , any idea why and what can be done ? I still have difficult to understand why when I place the data from column E ad to the right , it work , but when I try to execute the same macro when the data start from column A it does not work , I also want to mentioned that when I place the data from column A , I also changed in the code the line: "For i = 5 To 23 Step 2" to "For i = 1 To 23 Step 2" and still it does not work I am talking on the macro in module2 I upload the sheet again for your reference



Enter Debug Mode when the error is prompted and check the copied range. The error you're getting sounds to me like the range is empty.
 

Attachments

  • datafrom server 4weeks.xls
    77 KB · Views: 1
Hi, Pilot5000!

You have a For...Next loop ranging from 5 to 23. 23rd column is W, but it's empty, data ranges only thru column U, 21. Hence you're out of boundaries.

So try replacing 23 by 21 and check if you get the expected results.

Regards!
 
Back
Top