вы можете использовать AutoFilter()
With Range("A1", Cells(Rows.Count, 1).End(xlUp))
.Rows(1).EntireRow.Insert ' insert temporary row for dummy headers
With .Offset(-1).Resize(.Rows.Count + 1)
.Range("A1:B1").Value = Array("h1", "h2") ' write dummy headers
.AutoFilter field:=1, Criteria1:=Application.Transpose(Range("B1", Cells(Rows.Count, 2).End(xlUp)).Value), Operator:=xlFilterValues
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).ClearContents
.Parent.AutoFilterMode = False
.Rows(1).EntireRow.Delete ' remove dummy headers temporary row
End With
End With
Range("B1", Cells(Rows.Count, 2).End(xlUp)).ClearContents ' clear column B values
или с Find()
Dim cel As Range
With Range("B1", Cells(Rows.Count, 2).End(xlUp))
For Each cel In Range("A1", Cells(Rows.Count, 1).End(xlUp))
If Not .Find(what:=cel.Value, LookIn:=xlValues, lookat:=xlWhole) Is Nothing Then cel.ClearContents
Next
.ClearContents
End With
, что, если сохранение «верхов» наверху будет проблемой, становится:
Dim cel As Range, s As String
With Range("B1", Cells(Rows.Count, 2).End(xlUp))
For Each cel In Range("A1", Cells(Rows.Count, 1).End(xlUp))
If Not .Find(what:=cel.Value, LookIn:=xlValues, lookat:=xlWhole) Is Nothing Then s = s & cel.Address(False, False) & " "
Next
.ClearContents
End With
If s <> vbNullString Then Range(Replace(Trim(s), " ", ",")).Delete xlUp