VBA; Copy and paste row on condition

Das1987

New Member
Joined
Dec 19, 2012
Messages
9
Hello,

I have tried to write some VBA to copy and paste rows of data based on a condition. So far I have only been able to copy the first cell. It would be appreciated if someone could point out where I am going wrong so that I know in future.

Code:
Sub CopytoOtherSht()
    Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).AutoFilter 1, "WISBECH ROADWAYS  CUSTOMERS"
    Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row).Copy Sheets(2).Range("A" & Rows.Count).End(xlUp)(2)
    Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).AutoFilter
End Sub

Many thanks in advance.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
When pasting a range of data, you only need to paste it to the last available cell.
Example
Code:
Sub CopyFilteredData()

    Dim Rws As Long, Rng As Range


    Rws = Cells(Rows.Count, "A").End(xlUp).Row

    Set Rng = Range(Cells(2, 1), Cells(Rws, 1))

    Range("A1").AutoFilter Field:=1, Criteria1:="WISBECH ROADWAYS  CUSTOMERS"
    Rng.Copy Destination:=Worksheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    Range("A1").AutoFilter

End Sub
 
Last edited:
Upvote 0
Thanks for that, but it still only copies Column A.

Not sure I explained well enough but what I wanted to do is copy and paste the entire row of data where column A matches the criteria.
 
Upvote 0

Forum statistics

Threads
1,207,402
Messages
6,078,264
Members
446,324
Latest member
JKamlet

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