Copy doesn't work

Status
Not open for further replies.

Demirion

Board Regular
Joined
Sep 21, 2022
Messages
66
Platform
  1. Windows
Hi, this code works:
VBA Code:
Worksheets("Ark1").Range(Cells(1, 1), Cells(lRow, lCol)).Copy Worksheets("Ark2").Range("A1")

but I want to copy data from the second row it doesn't work and error is displayed "Run-time error 1004. Application-definded or object-defined error":
VBA Code:
Worksheets("Ark1").Range(Cells(2, 1), Cells(lRow, lCol)).Copy Worksheets("Ark2").Range("A1")

What went wrong?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You need to qualify all ranges with the sheet name like
VBA Code:
With Worksheets("Ark1")
   .Range(.Cells(1, 1), .Cells(lRow, lCol)).Copy Worksheets("Ark2").Range("A1")
End With
 
Upvote 0
But the first code works for Range(Cells(1, 1) and doesn't work for Range(Cells(2, 1). I want the second one to start working:
VBA Code:
Worksheets("Ark1").[B]Range(Cells(2, 1), Cells(lRow, lCol)).Copy Worksheets("Ark2").Range("A1")
 
Last edited:
Upvote 0
Just use the same structure that I showed.
That code will only work if the relevant sheet is active.
 
Upvote 0
I want to copy from another workbook with multiple sheets and paste into a second workbook with multiple sheets.
VBA Code:
With Workbook1
.Sheets("A").Range(.Cells(2, 1), .Cells(lRow, lCol))) Copy
ThisWorkbook.Sheets("Ark1").Range("A2").PasteSpecial xlPasteValues
End With

This is my code snippet. Why doesn't it work?
 
Upvote 0
Because you are not qualifying the ranges with the sheet name. It should be like
VBA Code:
With Workbook1.Sheets("A")
   .Range(.Cells(2, 1), .Cells(lRow, lCol)).Copy
   ThisWorkbook.Sheets("Ark1").Range("A2").PasteSpecial xlPasteValues
End With
 
Upvote 0
Why is it only pasting one A2 cell to ThisWorkbook.Sheets("Ark1")?

Is it possible to do this for multiple sheets, e.g. like this:
VBA Code:
With Workbook1
.Sheets("A").Range(.Cells(2, 1), .Cells(lRow, lCol))) Copy
ThisWorkbook.Sheets("Ark1").Range("A2").PasteSpecial xlPasteValues

.Sheets("B").Range(.Cells(2, 1), .Cells(lRow, lCol))) Copy
ThisWorkbook.Sheets("Ark2").Range("A2").PasteSpecial xlPasteValues

.Sheets("C").Range(.Cells(2, 1), .Cells(lRow, lCol))) Copy
ThisWorkbook.Sheets("Ark3").Range("A2").PasteSpecial xlPasteValues

End With
 
Upvote 0
You have not done what I showed.
 
Upvote 0
Unfortunately, in this form, it only pastes the data into cell A2
VBA Code:
 With Workbook1.Sheets("A")
 .Range(.Cells(2, 1), .Cells(lRow, lCol)).Copy
 ThisWorkbook.Sheets("Ark1").Range("A2").PasteSpecial xlPasteValues
End With

Yes but is there a way to do this for a lot of sheets in an easier way?

Instead of this:
VBA Code:
With Workbook1.Sheets("A")
 .Range(.Cells(2, 1), .Cells(lRow, lCol)).Copy
 ThisWorkbook.Sheets("Ark1").Range("A2").PasteSpecial xlPasteValues
End With

With Workbook1.Sheets("B")
 .Range(.Cells(2, 1), .Cells(lRow, lCol)).Copy
 ThisWorkbook.Sheets("Ark2").Range("A2").PasteSpecial xlPasteValues
End With

Something like this:
VBA Code:
With Workbook1

.Sheets("A").Range(.Cells(2, 1), .Cells(lRow, lCol))) Copy
ThisWorkbook.Sheets("Ark1").Range("A2").PasteSpecial xlPasteValues

.Sheets("B").Range(.Cells(2, 1), .Cells(lRow, lCol))) Copy
ThisWorkbook.Sheets("Ark2").Range("A2").PasteSpecial xlPasteValues

End With
 
Upvote 0
You can nest with statements like
VBA Code:
With Workbook1
   With .Sheets("A")
      .Range(.Cells(2, 1), .Cells(lRow, lCol)).Copy
      ThisWorkbook.Sheets("Ark1").Range("A2").PasteSpecial xlPasteValues
   End With

   With .Sheets("B")
    .Range(.Cells(2, 1), .Cells(lRow, lCol)).Copy
    ThisWorkbook.Sheets("Ark2").Range("A2").PasteSpecial xlPasteValues
   End With
End With
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,986
Messages
6,128,118
Members
449,423
Latest member
Mike_AL

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