Опция Явная
Private D1 As Variant
Private RSel As Range
Private R2Del As Range
Public Sub Squadra_Unita(Optional ByVal msg As Variant) _
'https://youtu.be/sE6CMwO5Qm8
Rows_Delete _
Range_Walk( _
List_Ask( _
Selection_Check))
End Sub
Public Function Rows_Delete(Optional ByVal msg As Variant) _
As Variant
If R2Del Is Nothing Then _
Exit Function
R2Del.EntireRow.Delete shift:=xlUp
End Function
Public Function Range_Walk(Optional ByVal msg As Variant) _
As Range
Dim x As Long
For x = LBound(D1) To UBound(D1)
Set R2Del = App_Union( _
R2Del, _
Search_Get(RSel, D1(x)))
Next
End Function
Public Function Search_Get(ByVal r As Range, ByVal str As String) _
As Variant
Dim c As Range, found As Range, firstAddress As String
With r
Set c = .Find( _
what:=str, LookAt:=xlPart, MatchCase:=False)
If Not c Is Nothing Then
firstAddress = c.Address
Do
Set found = App_Union(found, c)
Set c = .FindNext(c)
If c Is Nothing Then Exit Do
Loop While c.Address <> firstAddress
End If
End With
If Not found Is Nothing Then _
Set Search_Get = found
End Function
Public Function List_Ask(Optional ByVal msg As Variant) As Variant ' Òåñòîì ÍÅ ïîêðûòà
Dim str As String
str = Application.InputBox( _
"Type words with space", _
"List for Delete Rows in Selection", , , , , , 2)
D1 = Split(str)
End Function
Public Function Selection_Check(Optional ByVal msg As Variant) _
As Variant
If Selection.Count < 2 Then
MsgBox "Need more selection :-)"
End
Else
Set RSel = Application.Intersect( _
ActiveSheet.UsedRange, _
Selection)
End If
End Function
Public Function App_Union(rng_Union As Range, _
ByVal rng As Range) _
As Range
' Set rng_union = App_Union(rng_union, .Rows(x))
If Not rng_Union Is Nothing Then
Set rng_Union = Application.Union(rng_Union, rng)
Else
Set rng_Union = rng
End If
Set App_Union = rng_Union
End Function