Аналогично ответу Siddharth Rout , но с использованием столбца 'helper' и сортировкой для удаления строк.
Option Explicit
Sub D2()
Dim i As Long, j As Long, lc As Long, edt As Long, vals As Variant
With Worksheets("sheet1")
appTGGL bTGGL:=False
edt = Application.Min(.Range("U:U"))
lc = .Cells(1, .Columns.Count).End(xlToLeft).Column
'store worksheet values in array
vals = .Range(.Cells(2, "A"), .Cells(.Rows.Count, "U").End(xlUp).Offset(0, lc - 21)).Value
'vals = .CurrentRegion.Cells.Offset(1, 0).Value
'add a sorting counter
lc = UBound(vals, 2) + 1
ReDim Preserve vals(LBound(vals, 1) To UBound(vals, 1), _
LBound(vals, 2) To lc)
For i = LBound(vals, 1) To UBound(vals, 1)
vals(i, lc) = i
Next i
'clear array values
For i = LBound(vals, 1) To UBound(vals, 1)
If vals(i, 21) = edt Then
Select Case UCase(vals(i, 19))
Case "AAA", "BBB", "CCC"
For j = LBound(vals, 2) To UBound(vals, 2): vals(i, j) = vbNullString: Next j
End Select
Else
Select Case UCase(vals(i, 19))
Case "AAA", "BBB", "CCC"
Case Else
For j = LBound(vals, 2) To UBound(vals, 2): vals(i, j) = vbNullString: Next j
End Select
End If
Next i
With .Cells(2, "A").Resize(UBound(vals, 1), UBound(vals, 2))
'return values to worksheet
.Value = vals
'sort on the additional column
.Cells.Sort Key1:=.Columns(lc), Order1:=xlAscending, _
Orientation:=xlTopToBottom, Header:=xlNo
End With
'clear the sorting index column
.Cells(1, lc).EntireColumn.Clear
End With
appTGGL
End Sub
Public Sub appTGGL(Optional bTGGL As Boolean = True)
Application.ScreenUpdating = bTGGL
Application.EnableEvents = bTGGL
Application.DisplayAlerts = bTGGL
Application.Calculation = IIf(bTGGL, xlCalculationAutomatic, xlCalculationManual)
Debug.Print Timer
End Sub