VBA Delete rows based on array?

Hendrixx

New Member
Joined
Nov 14, 2017
Messages
17
Hi all,

Newbie here.

I have a list of 16 9-digit numbers.

I have a worksheet with approx 1,000 9-digit numbers in Column A and other data in other columns.
I would like to use VBA to delete all rows in which one of the 16 9-digit numbers is in Column A.
I thought of placing the 16 9-digit numbers in an array and deleting rows based on comparing Column A with this array but can’t work out how to do it
Is this possible?
I have searched around and can’t find exactly what I’m looking for, and have had some success in deleting single rows, but not all of them.

I can’t post my code as I’m currently in the train….but I’m thinking I’ll have to start from scratch again anyway.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Will the 16 9-digit numbers always be the same and never change over time?
 
Upvote 0
This should do what you want (replace the 16 test numbers I used with your actual 9-digit numbers)...
VBA Code:
Sub RemoveRowMatchingNumbers()
  Dim Num As Variant
  For Each Num In Array(111111111, 222222222, 333333333, 444444444, _
                        555555555, 666666666, 777777777, 888888888, _
                        999999999, 121212121, 343434343, 565656565, _
                        787878787, 898989898, 123123123, 987987987)
    Columns("A").Replace Num, "", xlWhole, , , , False, False
  Next
  Columns("A").SpecialCells(xlBlanks).EntireRow.Delete
End Sub
 
Upvote 0
Solution
Wow, that looks much simpler than whatever it was that I was doing.

Thanks Rick. I'll give it a try and report back with a "Mark as solution".

I appreciate your help.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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