Anytime you delete a row from a worksheet you take a SIGNIFICANT performance hit. This obviously becomes an issues when you have lots of rows to delete.
I duplicated the contents in lucas' original workbook down until I reached row 6000. When I then ran his original code on my laptop it took almost 50 secs to complete. His modified code using autofiltering still took over 5 secs. That may be considered acceptable, but if you were to take the whole process into memory and were to access the worksheet only twice, first to read the data and finally, after deleting the rows in memory, to paste the modified data back to the worksheet, you could obtain an enormous performance acceleration. The code below took on my laptop less than 0.2 secs to complete. That's a 250x(!!!) improvement over the original code, and still a 25x improvement over the code with autofiltering! Give it try.
Sub DeleteMultipleStringRows_InMemory()
If ActiveSheet.UsedRange.Cells.Count = 1 Then Exit Sub
Dim targetColumn As Long
targetColumn = Columns("K").Column - ActiveSheet.UsedRange.Cells(1, 1).Column + 1
If targetColumn < 1 Then
MsgBox ("Column K is empty")
Exit Sub
End If
Dim startTime As Double
startTime = Timer
Dim db As Variant
db = ActiveSheet.UsedRange
Dim rToDelete() As Long
ReDim rToDelete(0)
Dim iRow As Long
For iRow = 1 To UBound(db, 1)
If db(iRow, targetColumn) Like "PREXP" _
Or db(iRow, targetColumn) Like "EFT" _
Or db(iRow, targetColumn) Like "AD" _
Then
ReDim Preserve rToDelete(UBound(rToDelete, 1) + 1)
rToDelete(UBound(rToDelete, 1)) = iRow
End If
Next iRow
db = DeleteMultipleRowsFromArray(db, rToDelete())
Dim targetRange As Range
Set targetRange = Range(ActiveSheet.UsedRange.Cells(1, 1), ActiveSheet.UsedRange.Cells(UBound(db, 1), _
UBound(db, 2)))
targetRange.Select
ActiveSheet.UsedRange.Clear
targetRange = db
Debug.Print "Elaped time: " & Timer - startTime & "sec"
End Sub
Function DeleteMultipleRowsFromArray(a As Variant, rowsToDelete() As Long) As Variant
'rowsToDelete must contain the numbers of the rows to delete
'in increasing order
Dim n() As String
ReDim n(1 To UBound(a, 1) - UBound(rowsToDelete, 1), 1 To UBound(a, 2))
Dim iRowOriginal
Dim iRowToDelete
iRowToDelete = 1
Dim iRowNew, iCol As Long
iRowNew = 1
For iRowOriginal = 1 To UBound(a, 1)
If iRowOriginal = rowsToDelete(iRowToDelete) Then
If iRowToDelete < UBound(rowsToDelete) Then iRowToDelete = iRowToDelete + 1
Else
For iCol = 1 To UBound(a, 2)
n(iRowNew, iCol) = a(iRowOriginal, iCol)
Next iCol
iRowNew = iRowNew + 1
End If
Next iRowOriginal
DeleteMultipleRowsFromArray = n
End Function
Hope this helped,
Rolf