delete all rows in a worksheet except selected rows identified by an ID number

Worksheet named "Original"  contains thousands of rows, and in Column A there is an ID number. Each ID number is unique.

Worksheet named IDList contains a few hundred ID numbers.

The objective is to delete all rows in "Original" worksheet, that are different from the ID numbers in "IDList" worksheet.

Excel file is attached.
Original-and-IDList.xlsx
gregfthompsonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

[ fanpages ]IT Services ConsultantCommented:
Formula in cell [H4]:
=MATCH(A4,IDList!A:A,0)

Copy down column [H] to row 12449.

Set a filter on cell [H3], & select all cells with a value of #N/A.

Select all rows shown in the Filtered list.

Delete the rows.

See attachment: "Q_28844739.xlsx".

Reset the Filter on cell [H3] to "All".

See attachment: "Q_28844739b.xlsx".

Delete copy [H].
Q_28844739.xlsx
Q_28844739b.xlsx

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Or you may try this code to delete all the rows from original sheet if the id's don't exit on the IDList sheet.
Please find the attached workbook where on Original sheet, you may click the button to delete the unwanted rows.

Sub DeleteRows()
Dim lr As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, 3).End(xlUp).Row
Range("G4:G" & lr).Formula = "=MATCH(A4,IDList!A:A,0)"
On Error Resume Next
Range("G:G").SpecialCells(xlCellTypeFormulas, 16).EntireRow.Delete
Range("G4:G" & lr).Clear
Application.ScreenUpdating = True
MsgBox "Rows deleted successfully.", vbInformation, "Done!"
End Sub

Open in new window

Original-and-IDList.xlsm
gregfthompsonAuthor Commented:
Brilliant. Thanks.
[ fanpages ]IT Services ConsultantCommented:
You're welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.