I'm trying to write a VBA script which will delete all rows in my Excel spreadsheet where Column I (which contains a status code) does not contain the word "Completed".
At the moment, I'm doing this the other way round: my script is able to search for entries in Column I which contain the status codes "Pending", "Awaiting Authorisation", "In Progress" etc and delete them. The idea is that when all those rows are deleted, I'll only be left with rows which have a status of "Completed". This works fine at the moment. However, the concern is that if a brand new status code is added to the data file, my script would be unable to pick it up and delete it.
This is a small sample of the code I'm currently using (which deletes all the rows with statuses other than Completed):
Dim rng As Range
Dim search_string As String: search_string = "Pending"
Dim lng_i As Long
For lng_i = 1 To Application.CountIf(Columns(9), search_string) Step 1
With ActiveSheet.Range("I:I"): .Find(search_string, LookIn:=xlValues).EntireRow.Delete: End With
Next lng_i
How can I re-write this so that it will delete all the rows where the status does not contain "Completed", regardless of whether new status codes are added in the future?
Bookmarks