Hi Excel folks,
I m trying to move every second row at the end of previous row.
This below code is being applied from the third row. I m getting the desired out , but i m also getting the below error.
" run-time error 1004 : Application-defined or object-defined error".
I m aware that error is in the below red line, but why is that an error
Can anyone help me out with where is the error in this code?
sub merging()
Dim sh As Worksheet, lr As Long, lc As Long
Set sh = Sheet4 'Edit sheet name.
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 1 Step -2
With sh
.Range(.Cells(i, 1), .Cells(i, Columns.Count).End(xlToLeft)).Copy .Cells(i - 1, Columns.Count).End(xlToLeft).Offset(0, 1)
.Rows(i).Delete
End With
Next
End Sub
any help will be very appreciated
Best,
Manvit
I m trying to move every second row at the end of previous row.
This below code is being applied from the third row. I m getting the desired out , but i m also getting the below error.
" run-time error 1004 : Application-defined or object-defined error".
I m aware that error is in the below red line, but why is that an error
Can anyone help me out with where is the error in this code?
sub merging()
Dim sh As Worksheet, lr As Long, lc As Long
Set sh = Sheet4 'Edit sheet name.
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 1 Step -2
With sh
.Range(.Cells(i, 1), .Cells(i, Columns.Count).End(xlToLeft)).Copy .Cells(i - 1, Columns.Count).End(xlToLeft).Offset(0, 1)
.Rows(i).Delete
End With
Next
End Sub
any help will be very appreciated
Best,
Manvit
Last edited: