وعليكم السلام ورحمه الله وبركاته
تفضل اخى
Private Sub CommandButton1_Click()
Dim Ws As Worksheet, Arr, dic As Object, Levels, X
Dim i As Long, R As Long, j As Long, P As Long
Set Ws = ThisWorkbook.Worksheets("main")
Arr = Ws.Range("A2:B" & Ws.Cells(Rows.Count, 1).End(xlUp).Row).Value
Set dic = CreateObject("Scripting.Dictionary")
R = 1
Levels = Array(TextBox1, TextBox2, TextBox3)
Me.ListBox1.Clear
ReDim B(1 To UBound(Arr, 1))
For i = LBound(Arr, 1) To UBound(Arr, 1)
If Not dic.Exists(Arr(i, 1)) Then
dic.Add Arr(i, 1), R
B(R) = Arr(i, 1) & "-" & Split(Arr(i, 2))(0)
R = R + 1
Else
B(dic(Arr(i, 1))) = B(dic(Arr(i, 1))) & "-" & Split(Arr(i, 2))(0)
End If
Next i
ReDim Tmp(1 To R - 1)
For i = LBound(B, 1) To R - 1
If UBound(Split(B(i), "-")) = UBound(Levels) + 1 Then
For j = 1 To UBound(Levels) + 1
X = Application.Match(Split(B(i), "-")(j), Levels, 0)
If IsError(X) Then GoTo 1
Next j
P = P + 1
Tmp(P) = Split(B(i), "-")(0)
End If
1 Next i
If P > 0 Then Me.ListBox1.List = Application.Index(Tmp, Evaluate("row(1:" & P & ")"))
End Sub
test.xlsm