I have a ListObject table with ~500 rows, I've also got 4 values in a named range.
There are maybe 30 unique values that occur repeatedly (At random) for the 500 rows, I want to delete all rows whose values are not in the named range.
I have the following which works, but it is running slower than expected (approximately 2 min):
Sub removeAccounts()
Dim tbl As ListObject
Dim i As Integer
Set tbl = ThisWorkbook.Sheets("TheSheet").ListObjects("TheTable")
i = tbl.ListRows.Count
While i > 0
If Application.WorksheetFunction.CountIf(Range("Included_Rows"), tbl.ListRows(i).Range.Cells(1).Value) = 0 Then
tbl.ListRows(i).Delete
End If
i = i - 1
Wend
End Sub
I'm not sure whether it's the reliance on the worksheet function or just looping through the rows that is slowing it down.
Is there a way to filter the listobject and discard the rest?
I was thinking of just chucking a progress bar on it so that the users can see something happening...