VBA copy row of data based on column value

fordmudslinger

Board Regular
Joined
Apr 4, 2015
Messages
64
I have a spreadsheet that i would like to have a row copied from sheet 1 if the value in column f is "L" in that same row. then have the entire row pasted into sheet 2. Please help
 
Try this:

When seeking help specific details are important:

Code:
Sub Copy_rows_in_a_table()
'Copy rows in a table
'Modified 11-29-17 12:55 PM EST
On Error GoTo M
Dim RngToCopy As Range
Range("Table2").Select
    ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=5, Criteria1:="L"
    Set RngToCopy = Selection.Offset(-1, 0).SpecialCells(xlCellTypeVisible)
    Selection.AutoFilter
    RngToCopy.Copy Sheets("Sheet2").Range("A1")
    Range("Table2").AutoFilter
    
Exit Sub
M:
    MsgBox "No Rows with your criteria found"
  End Sub
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Perfect, thanks! I changed "Table2" to "Data" because that is the name of the table. I think you got "Sheet2" and the table name confused. Nonetheless, it works now! Thanks for your help. Sorry about the confusion with the table; I didn't know it made a difference, but I do now!
 
Upvote 0
Perfect, thanks! I changed "Table2" to "Data" because that is the name of the table. I think you got "Sheet2" and the table name confused. Nonetheless, it works now! Thanks for your help. Sorry about the confusion with the table; I didn't know it made a difference, but I do now!

Glad it worked for you.
And when you see Field:=5

That means the fifth column in your table
So if the first field is "B" then Field 5 would be "F"
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

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