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
 
How about:

VBA Code:
Sub Test()

    Dim ar() As String, rng As Range, i As Long
    
    ar = Split("Amitabh,Deepika Padukone,Anil Kapur,Madhuri,Salman Khan,Juhi Chawala,Shahrukh Khan,Karishma Kapoor,Hritik Roshan,Priyanka Chopra", ",")
    Set rng = Sheet1.Range(Sheet1.Range("c2:d2"), Sheet1.Range("c" & Rows.Count & ":" & "d" & Rows.Count).End(xlUp))
    
    For i = 1 To rng.Rows.Count
        If IsError(Application.Match(rng.Cells(i, 1), ar, 0)) And IsError(Application.Match(rng.Cells(i, 2), ar, 0)) Then
            If Len(rng.Cells(i, 1) & rng.Cells(i, 2)) Then
                rng.Cells(i, 1).EntireRow.Delete
            End If
        End If
    Next i

End Sub
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,216,117
Messages
6,128,937
Members
449,480
Latest member
yesitisasport

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