Delete Criteria Rows Efficiently
Sub DeleteCriteriaRows()
Const EMPTY_COL As Long = 6
Const VALUE_COL As Long = 11
Const FLAG_STRING As String = "!"
Dim DeleteStrings(): DeleteStrings = Array( _
"(2020PF OLD) WERNER EGERLAND NEUSEDDIN", _
"(2020PF OLD) SPEDITION HORST MOSOLF KORNWESTHEIM", _
"ALBIAS STELLANTIS VO (PFV)", "ATESSA ADJACENT STELLANTIS (PFV)", _
"BALESI LOCATIONS FIGARI (2020PF)", "CAT AULNAY (2020PF)", _
"CAT AVRIGNY (2020PF)", "CAT BOURGOGNE CHALON (2020PF)", _
"CAT BOURGOGNE DIJON (2020PF)", "CAT GUASTICCE (2020PF)", _
"CAT TORRES DE LA ALAMEDA (2020PF)", "CAT VALE ANA GOMES (2020PF)", _
"SOGRITA BASTIA (2020PF)", "SOGRITA SARROLA AJACCIO (2020PF)", _
"TRNAVA STELLANTIS (PFV)")
Dim dict As Object: Set dict = CreateObject("Scripting.Dictionary")
dict.CompareMode = vbTextCompare
Dim Key: For Each Key In DeleteStrings: dict(Key) = Empty: Next Key
Dim ws As Worksheet: Set ws = ActiveSheet ' improve!
If ws.FilterMode Then ws.ShowAllData
If ws.AutoFilterMode Then ws.AutoFilterMode = False
Dim rg As Range: Set rg = ws.Range("A1").CurrentRegion ' has headers
Dim rCount As Long: rCount = rg.Rows.Count - 1
Dim drg As Range: Set drg = rg.Resize(rCount).Offset(1) ' no headers
Dim edrg As Range: Set edrg = drg.Columns(EMPTY_COL)
Dim vdrg As Range: Set vdrg = drg.Columns(VALUE_COL)
Dim eData(): eData = edrg.Value
Dim vData(): vData = vdrg.Value
Dim r As Long, IsKept As Boolean, WasFlagged As Boolean
For r = 1 To rCount
If Not IsEmpty(eData(r, 1)) Then ' not empty
'If Len(CStr(eData(r, 1))) > 0 Then ' not blank
If Not dict.Exists(CStr(vData(r, 1))) Then IsKept = True
End If
If IsKept Then
IsKept = False ' reset for the next iteration
Else
vData(r, 1) = FLAG_STRING
If Not WasFlagged Then WasFlagged = True ' only once; never reset
End If
Next r
If Not WasFlagged Then
MsgBox "No values matching the criteria found.", vbExclamation
Exit Sub
End If
Application.ScreenUpdating = False
vdrg.Value = vData
drg.Sort vdrg, xlAscending, , , , , , xlNo ' It won't take forever...
rg.AutoFilter VALUE_COL, FLAG_STRING
Dim vrg As Range: Set vrg = drg.SpecialCells(xlCellTypeVisible)
ws.AutoFilterMode = False
vrg.Delete xlShiftUp ' ,,, if a single area is being deleted.
drg.Sort edrg, xlAscending, , , , , , xlNo
Application.ScreenUpdating = True
MsgBox "Criteria rows deleted.", vbInformation
End Sub