Sub XYZ()
Dim aData(), aSP(), res(), arr(), S, aL, aU, sp$
Dim srData&, srSP&, N&, D&, i&, j&, k&, r&
aL = Array(0, 1, 0, 1, 0, 2, 3, 0, 2, 1, 4, 0, 3, 1, 2)
aU = Array(0, 0, 1, 1, 2, 0, 0, 3, 1, 2, 0, 4, 1, 3, 2)
N = UBound(aL)
With Sheets("Sheet1")
aData = .Range("A2", .Range("B" & Rows.Count).End(xlUp)).Value
End With
With Sheets("Sheet2")
aSP = .Range("A2", .Range("A" & Rows.Count).End(xlUp)).Value
End With
srData = UBound(aData): srSP = UBound(aSP)
ReDim res(1 To srSP, 1 To 2)
For i = 1 To srData
aData(i, 1) = Application.Trim(Replace(aData(i, 1), "!", "! "))
Next i
For i = 1 To srSP
S = Split(Application.Trim(Replace(aSP(i, 1), "!", "! ")), " ")
D = UBound(S)
For j = 0 To N
If D - aL(j) - aU(j) > 0 Then
ReDim arr(aL(j) To D - aU(j))
For k = aL(j) To D - aU(j)
arr(k) = S(k)
Next k
sp = Join(arr, " ")
For r = 1 To srData
If InStr(1, aData(r, 1), sp, vbTextCompare) > 0 Then
res(i, 1) = aData(r, 2)
res(i, 2) = aData(r, 1)
GoTo Tiep
End If
Next r
End If
Next j
Tiep:
Next i
Sheets("Sheet2").Range("B2").Resize(srSP, 2) = res
End Sub