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?
 
Code didn't work because I used it "Application.CutCopyMode = False". Why did it cause only one cell to paste?
VBA Code:
With Workbook1.Sheets("A")

 .Range(.Cells(2, 1), .Cells(lRow, lCol)).Copy
 ThisWorkbook.Sheets("Ark1").Range("A2").PasteSpecial xlPasteValues
Application.CutCopyMode = False

End With

All clear. Thank you.
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Why did it cause only one cell to paste?
difficult to tell as you haven't posted all the code, but best guess is that lrow & lcol are not what you think they should be.
 
Upvote 0
I thought it "Application.CutCopyMode = False" worked the other way so I have no idea why only one cell is pasted through it.
 
Upvote 0
That line just clears the clipboard & has nothing to do with it only pasting one cell.
 
Upvote 0
I know and it's weird because when I removed CutCopyMode it started working. Otherwise, it only pastes one cell. Unless I made a mistake. I don't get tired anymore. Thanks one more time.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0
One cell is pasted again. I tried to change lRow to xlDown and lCol to xlToRight and message displayed "Run-time error 1004. You cant paste this here because the Copy area and paste area aren't the same size. Select just one cell in the paste area or area that's the same size, and try pasting again." What's the problem?
 
Upvote 0
lRow = Cells(Rows.Count, 1).End.(xlUp).Row
lCol = Cells(1, Columns.Count).End.(xlToLeft).Column

Maybe there is something wrong with this?
 
Upvote 0
What are the actual values of those two variables?
 
Upvote 0
I already know what the problem is. Row in Column I gave at the very beginning of the macro and counted something else. So I understand that for each sheet I should do something like this?
VBA Code:
With Workbook1
 With .Sheets("A")
lRow = .Cells(Rows.Count, 1).End.(xlUp).Row
lCol = .Cells(1, Columns.Count).End.(xlToLeft).Column
.Range(.Cells(2, 1), .Cells(lRow, lCol)).Copy
 ThisWorkbook.Sheets("Ark1").Range("A2").PasteSpecial xlPasteValues
 End With

 With .Sheets("B")
lRow = .Cells(Rows.Count, 1).End.(xlUp).Row
lCol = .Cells(1, Columns.Count).End.(xlToLeft).Column
.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,201
Messages
6,123,617
Members
449,109
Latest member
Sebas8956

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