一維轉二維//去重//一個字典//一次迴圈完成...by.准提部林
Sub Test_A1()
Dim Arr, Brr, xD, i&, TT$, T1$, T2$, R&, C&, X&, Y&
Set xD = CreateObject("scripting.dictionary")
Arr = Range([b1], [a65536].End(3))
ReDim Brr(1 To UBound(Arr), 1 To 200)
For i = 2 To UBound(Arr)
T1 = Arr(i, 1): T2 = T1 & "+": TT = T1 & Arr(i, 2)
If xD(T1) = 0 Then X = X + 1: xD(T1) = X: Brr(X, 1) = T1
R = xD(T1): C = xD(T2)
If xD(TT) = 0 Then
C = C + 1: xD(T2) = C: xD(TT) = C
Brr(R, C + 1) = Arr(i, 2)
If C > Y Then Y = C
End If
Next i
[d7].Resize(X, Y + 1) = Brr
End Sub
|