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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You have still not answered my question, so I don't know.
 
Upvote 0
I did as before, i.e. I gave lRow and lCol at the beginning. They have lRow=63 and lCol=1
 
Upvote 0
In that case your code should paste A2:A63 from one sheet to the other.
 
Upvote 0
Where to put lRow and lCol so that it works properly for each of the sheets that are different from each other? I don't know where these numbers came from, the values should be completely different.
 
Upvote 0
There is nothing wrong with the code I suggested & as I said before there should not be a problem.
Without your workbook I have no idea what the problem is. Also you just keep posting different bits of code, so I have no idea what your real code is.
 
Upvote 0
But I showed everything most important. Just tell me how to make lRow and lCol work properly or how to do it without variables? The idea is to copy data from multiple sheets from one workbook to another workbook to multiple sheets.
 
Upvote 0
I cannot tell you that because I have no idea what you are trying to do, what your data is like or the rest of your code is.
As your original question has been answered, if you need more help then you need to start a new thread.
 
Upvote 0
VBA Code:
Dim Workbook1 As Workbook
Dim lRow As Long
Dim lCol As Long
lRow = Cells(Rows.Count, 1).End.(xlUp).Row
lCol = Cells(1, Columns.Count).End.(xlToLeft).Column

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


This is what my code looks like. So you're saying that everything is fine with it and lRow and lCol should work fine for all sheets?
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,214
Messages
6,123,661
Members
449,114
Latest member
aides

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