У вас может быть эта функция на стандартном модуле ...
Function DeleteFromRange1(ByVal Rng1 As Range, ByVal Rng2 As Range) As Variant
Dim x, y, z(), dict
Dim i As Long, j As Long
Set dict = CreateObject("Scripting.Dictionary")
x = Rng1.Value
y = Rng2.Value
For i = 1 To UBound(y, 1)
dict.Item(y(i, 1)) = ""
Next i
For i = 1 To UBound(x, 1)
If dict.exists(x(i, 1)) Then
j = j + 1
ReDim Preserve z(1 To j)
z(j) = x(i, 1)
End If
Next i
DeleteFromRange1 = z
End Function
Затем вы можете вызвать эту функцию из вашего макроса, как показано ниже.
Не забудьте установить Rng1 и Rng2 согласно вашему требованию перед вызовом функции.
Sub CleanProjectLists()
Dim Rng1 As Range, Rng2 As Range
Dim arr
Application.ScreenUpdating = False
'Set your Range1 here
'Set Rng1 = .....
'Set your Range2 here
'Set Rng2 = .....
'Then call this function
arr = DeleteFromRange1(Rng1, Rng2)
Rng1.Clear
Rng1.Cells(1).Resize(UBound(arr), 1).Value = Application.Transpose(arr)
Application.ScreenUpdating = True
End Sub