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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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