Help with Copying a row if a value is in a column

Aditi208

New Member
Joined
Aug 26, 2014
Messages
1
Hello,

I am trying to make my excel sheet copy an entire row of data to a new sheet if the column contains a certain criteria. Specifically:

on the worksheets named: All results 1882-1900, All results 1900-1950, and All results 1950-2000

If Column F contains W then copy the whole row to a sheet named Wins

I have tried altering the code on several tutorials of the exact same thing and for the life of me I can't get it to work. Can anyone tell me how to properly write this code and put it in the excel sheet so it works?

Thanks!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try this ... UNTESTED

Code:
Sub MM1()
Dim lr As Long, r As Long, ws As Worksheet, lr2 As Long
lr2 = Sheets("Wins").Cells(Rows.Count, "A").End(xlUp).Row
For Each ws In Worksheets
If ws.Name = "All results 1882-1900" Or ws.Name = "All results 1900-1950" Or ws.Name = "All results 1950-2000" Then
    ws.Activate
    lr = ws.Cells(Rows.Count, "F").End(xlUp).Row
        For r = 1 To lr
            If ws.Range("F" & r).Value = "W" Then
                Rows(r).Copy Destination:=Sheets("Wins").Range("A" & lr2 + 1)
               lr2 = Sheets("Wins").Cells(Rows.Count, "A").End(xlUp).Row
            End If
        Next r
End If
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,563
Messages
6,125,572
Members
449,237
Latest member
Chase S

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