'Copy rows and paste at the end of another sheet
I want to copy rows 3 and below from Sheet2 and paste at the end of Sheet1. Rows in Sheet2 have different lengths. Not sure if I am selecting row3 and then row4, 5, etc. until end of sheet2.
My code so far. I am getting errors:
Sub Macro5()
Dim LastRow As Long
Worksheets("Sheet2").Activate
With ActiveSheet.UsedRange
LastRow = .Rows(.Rows.Count).Row
.Cell("A", 3).EntireRow.Select
Do Until LastRow
Selection.Copy
Sheets("Sheet1").Range("A1").End(xlDown).Offset(1, 0).Paste
Loop
End With
End Sub
Should I set a range from row3 - lastrow and loop through range?
Solution 1:[1]
You can just copy from row 3 till the end of Sheet 2 using the following code:
Public Sub copy_rows()
Dim LastRow As Long
LastRow = Worksheets("Sheet2").UsedRange.Rows.count
Worksheets("Sheet2").Rows("3:" & LastRow).Select
Selection.Copy
End Sub
Solution 2:[2]
Hope you are looking for this code.
Sub copy()
Dim Lastrow As Long
Lastrow = Sheets("Sheet2").UsedRange.Rows.Count
For i = 3 To Lastrow
Sheets("Sheet2").Rows(i).copy Sheets("Sheet1").Range("A" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row + 1)
Next i
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shai Rado |
| Solution 2 | Karthick Gunasekaran |
