|
Sub qs()
Dim arr, i, dic
Set dic = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
With Sheet1
arr = .Range("a1").CurrentRegion.Value
ReDim br(1 To UBound(arr), 1 To 2)
ReDim cr(1 To UBound(arr), 1 To 2)
For i = 2 To UBound(arr)
s = arr(i, 1)
If Not dic.exists(s) Then
dic(s) = arr(i, 2)
Else
If InStr(dic(s), arr(i, 2)) = 0 Then
dic(s) = dic(s) & "|" & arr(i, 2)
End If
End If
ss = arr(i, 2)
If Not d2.exists(ss) Then
d2(ss) = arr(i, 1)
Else
If InStr(d2(ss), arr(i, 1)) = 0 Then
d2(ss) = d2(ss) & "|" & arr(i, 1)
End If
End If
Next
For Each k In dic.keys
t = Split(dic(k), "|")
If UBound(t) > 0 Then
For x = 0 To UBound(t)
m = m + 1
br(m, 1) = k
br(m, 2) = "'" & t(x)
Next
End If
Next
For Each kk In d2.keys
tt = Split(d2(kk), "|")
If UBound(tt) > 0 Then
For xx = 0 To UBound(tt)
mm = mm + 1
cr(mm, 2) = "'" & kk
cr(mm, 1) = tt(xx)
Next
End If
Next
.Range("d2").Resize(m, 2) = br
.Range("g2").Resize(mm, 2) = cr
End With
Set dic = Nothing: Set d2 = Nothing
End Sub
|
|