|
try this:
- Sub zz()
- Dim a, b(), ar, s$, ss$, k, t
- With Sheets(2)
- a = .Range("a2:c" & .[a1048576].End(3).Row).Value
- End With
- With Sheets(1)
- ar = .Range("d2:g" & .[d1048576].End(3).Row).Value
- End With
- ReDim b(1 To UBound(ar), 1 To 3)
- For i = 1 To UBound(ar)
- For j = 1 To UBound(ar, 2)
- b(i, 3) = b(i, 3) & ar(i, j)
- Next
- For j = 1 To UBound(a)
- If InStr(ar(i, 1), a(j, 1)) Then
- b(i, 1) = a(j, 2): b(i, 2) = a(j, 3)
- Exit For
- End If
- Next
- Next
- With Sheets(3)
- a = .Range("a2:c" & .[c1048576].End(3).Row).Value
- End With
- ReDim ar(1 To UBound(a), 1 To 2)
- For i = 1 To UBound(a)
- s = Replace(Replace(LCase(a(i, 1)), "(", ""), ")", "")
- k = Split(s, "+")
- ss = "": s = ""
- For j = 0 To UBound(k)
- If InStr(k(j), "or") = 0 Then
- s = s & "|" & k(j)
- Else
- t = Split(k(j), "or")
- For jj = 0 To UBound(t)
- ss = ss & "|" & t(jj)
- Next
- End If
- Next
- ar(i, 1) = Split(Mid(s, 2), "|")
- ar(i, 2) = Split(Mid(ss, 2), "|")
- Next
- For i = 1 To UBound(b)
- If Len(b(i, 1)) = 0 Then
- For ii = 1 To UBound(ar)
- k = ar(ii, 1): t = ar(ii, 2): n = 0
- For j = 0 To UBound(k)
- If InStr(b(i, 3), k(j)) Then n = n + 1
- Next
- If n - 1 <> UBound(k) Then Exit For
- n = 0
- For j = 0 To UBound(t)
- If InStr(b(i, 3), t(j)) Then n = 1: Exit For
- Next
- If n Or UBound(t) = -1 Then
- b(i, 1) = a(ii, 2): b(i, 2) = a(ii, 3): Exit For
- End If
- Next
- End If
- Next
- [h2].Resize(UBound(b), 2) = b
- End Sub
复制代码
|
|