vba - Delete all rows except names contains in two lists

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I have two lists of Actors and Actress,
task is delete all actors and Actress whose name not in any of the list.

looking for answer in loop or array or dictionary , auto filter.

Below is Exclude list , Rest delete

ColumnA Column B
Actoractress
AmitabhDeepika Padukone
Anil KapurMadhuri
Salman KhanJuhi Chawala
Shahrukh KhanKarishma Kapoor
Hritik RoshanPriyanka Chopra


Thanks
mg
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Thanks for highlighting,

The list is in sheet2 and Data is in sheet1,

my actual data is in Column C and D of sheet1
which Contains Actor and actress long list,... from that list I want to keep Criteria list. rest actor and actress row want to delete.


Thanks
mg
 
Upvote 0
What happens if a row in one column has a valid actor\ess name and the same row in the other hasn't ?
 
Upvote 0
Hi Jafar,

then I don't want to delete that row...
actor actress
Salman khan, xxxx ....... I will not delete (as salman khan is in from actors list)
yyyyy Madhuri ......... I will not delete (as Madhuri is in from actress list)
xxxx yyyyy .............. I will delete ( as no actors from list and no actress from criteria list hence delete)

thanks
mg
 
Upvote 0
So in other words, you will only delete the row if both columns are not in the exclude list ?
 
Upvote 0
If you delete a row from an actor column, is there not a chance you would be deleting an actress that you wanted to keep?
 
Upvote 0
Yes , This is right :=>So in other words, you will only delete the row if both columns are not in the exclude list ?
 
Upvote 0
Give this a go,
VBA Code:
Sub GetErDun()
    Dim sh As Worksheet, ws As Worksheet
    Dim x As Long, LstRw As Long
    Dim Actr As Range, Actrs As Range

    Set sh = Sheets("Sheet1")
    Set ws = Sheets("Sheet2")

    With sh
        LstRw = .Cells(.Rows.Count, "C").End(xlUp).Row

        For x = LstRw To 2 Step -1
            Set Actr = ws.Cells.Find(.Cells(x, 3).Value, lookat:=xlWhole)
            Set Actrs = ws.Cells.Find(.Cells(x, 4).Value, lookat:=xlWhole)

            If Actr Is Nothing Or Actrs Is Nothing Then
                .Cells(x, 1).EntireRow.Delete
            End If
        Next x
    End With

End Sub
 
Upvote 0
Hi Dave,
Thanks for your help, need small change in it.
It is keeping only exact match data , say sheet2 ,

Salman Madhuri .... it is keeping exact match
I want exact match as well non exact match.(either one true from Criteria list) has to keep the data.

Regards,
mg
 
Upvote 0

Forum statistics

Threads
1,215,631
Messages
6,125,905
Members
449,273
Latest member
mrcsbenson

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