Paste to next empty row with VBA

scampie

New Member
Joined
Jul 6, 2015
Messages
18
I am trying to copy certain rows from one sheet to another which is working perfectly, but I need it to paste the data to the next empty row. Any help would be greatly appreciated.

VBA Code:
Sub TestEbay()

Dim Cell As Range

With Sheets("Ebay output")
    ' loop column H untill last cell with value (not entire column)
    For Each Cell In .Range("ad2:ad" & .Cells(.Rows.Count, "ad").End(xlUp).Row)
        If Cell.Value = "YES" Then
             ' Copy>>Paste in 1-line (no need to use Select)
            .Rows(Cell.Row).Copy Destination:=Sheets("Output sheet").Rows(Cell.Row)
        End If
    Next Cell
End With

End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Do you want all rows or just certain rows? Here is all rows...


VBA Code:
Sub TestEbay()
Dim cl As Object, strCells As String, lastRow As Long
With Sheets("Output sheet")
    lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With
With Sheets("Ebay output")
    strCells = "AD2:AD" & .Cells(.Rows.Count, "AD").End(xlUp).Row
    For Each cl In .Range(strCells)
        If cl.Value = "Yes" Then
            .Rows(cl.Row).Copy Destination:=Sheets("Output sheet").Range("A" & lastRow)
        End If
    Next cl
End With
End Sub
 
Upvote 0
I want to copy and paste all rows which have "YES" in the AD column. I have tried your code and it hasn't pasted anything. :(
 
Upvote 0
Sorry try this...


VBA Code:
Sub TestEbay()
Dim cl As Object, strCells As String, lastRow As Long
With Sheets("Ebay output")
    strCells = "AD2:AD" & .Cells(.Rows.Count, "AD").End(xlUp).Row
    For Each cl In .Range(strCells)
        If cl.Value = "Yes" Then
            With Sheets("Output sheet")
                lastRow = .Cells(.Rows.Count, "AD").End(xlUp).Row + 1
            End With
            .Rows(cl.Row).Copy Destination:=Sheets("Output sheet").Range("A" & lastRow)
        End If
    Next cl
End With
End Sub
 
Upvote 0
Do you have your sheet called "Output sheet"? Did you get any errors? It worked fine for me....
Yes, the code i added originally works, it just does not paste to the next empty row. No errors, just nothingness.
 
Upvote 0
Yes, the code i added originally works, it just does not paste to the next empty row. No errors, just nothingness.
Please try the code above. I changed the text.


VBA Code:
Sub TestEbay()
Dim cl As Object, strCells As String, lastRow As Long
With Sheets("Ebay output")
    strCells = "AD2:AD" & .Cells(.Rows.Count, "AD").End(xlUp).Row
    For Each cl In .Range(strCells)
        If cl.Value = "Yes" Then
            With Sheets("Output sheet")
                lastRow = .Cells(.Rows.Count, "AD").End(xlUp).Row + 1
            End With
            .Rows(cl.Row).Copy Destination:=Sheets("Output sheet").Range("A" & lastRow)
        End If
    Next cl
End With
End Sub
 
Upvote 0
Please take a screenshot of your "Output sheet"
 
Upvote 0
Annotation 2020-08-05 192821.jpg
 
Upvote 0
Please take a screenshot of the "Ebay output"... My code works for me
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,770
Members
449,095
Latest member
m_smith_solihull

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