Delete rows containing names from a list of names

NMB311

New Member
Joined
May 28, 2010
Messages
14
I'm wondering if there is a way to delete a whole row if that row contains a name from a list of names that I have. Here is an example from the data sheet (data):

Smith Robert 596 59609/07 08/22/11 MON WPS 0.37
Smith Robert 596 59609/07 08/26/11 FRI WPS 1.93
Gray Natalie 596 59617/09 08/25/11 THU LATE 0.80
Gray Natalie 596 59617/09 08/27/11 SAT OUT_EARLY 0.70
Peterson Colin 596 59605/06 08/22/11 MON LBRK 0.40
Peterson Colin 596 59605/06 08/22/11 MON OUT_EARLY 1.37
Peterson Colin 596 59605/06 08/25/11 THU WPS 0.28
Dustin Kim 596 59611/06 08/22/11 MON LBRK 0.27
Dustin Kim 596 59611/06 08/22/11 MON OUT_EARLY 1.38
Dustin Kim 596 59611/06 08/26/11 FRI WPS 0.30
Barber James 596 59627/07 08/23/11 TUE WNS 7.20
Dickerson Whitney 596 59612/11 08/22/11 MON WS 0.30
Young Sabrina 596 59625/11 08/25/11 THU 4.50

All of this information is in one column (A).

And here's the name list found in another sheet (leaders):

Leaders
Whitney Dickerson
Colin Peterson
Natalie Gray

I want to create a macro that will search for the leader names in the data sheet and delete the row that contains them. The list sometimes changes as well so I want the macro to compare the list to the data. Is there a way to do this?
 

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:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG17Sep27
[COLOR="Navy"]Dim[/COLOR] Rng     [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dn      [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Last    [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] n       [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Nam     [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
Last = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row
 [COLOR="Navy"]With[/COLOR] Sheets("Leaders")
 [COLOR="Navy"]Set[/COLOR] Rng = .Range(.Range("A1"), .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]For[/COLOR] n = Last To 1 [COLOR="Navy"]Step[/COLOR] -1
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
        [COLOR="Navy"]With[/COLOR] Sheets("Data").Range("A" & n)
            Nam = Split(.Value, " ")(1) & " " & Split(.Value, " ")(0)
            [COLOR="Navy"]If[/COLOR] Trim$(Dn) = Trim$(Nam) [COLOR="Navy"]Then[/COLOR] .EntireRow.Delete
        [COLOR="Navy"]End[/COLOR] With
    [COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

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