|
Option Explicit
Dim d_other As Object
Sub test()
Dim arr, brr, ar, crr(1 To 50000, 1 To 10)
Dim i&, j&, m&, x
Dim d_main As Object
Set d_other = CreateObject("scripting.dictionary")
Set d_main = CreateObject("scripting.dictionary")
arr = ActiveSheet.Range("a1").CurrentRegion
For i = 2 To UBound(arr)
If Val(Left(arr(i, 1), 2)) = 16 Then
If Not d_main.exists(arr(i, 1)) Then
d_main(arr(i, 1)) = Array(arr(i, 2))
Else
ar = d_main(arr(i, 1))
ReDim Preserve ar(UBound(ar) + 1)
ar(UBound(ar)) = arr(i, 2)
d_main(arr(i, 1)) = ar
End If
Else
If Not d_other.exists(arr(i, 1)) Then
d_other(arr(i, 1)) = Array(arr(i, 2))
Else
ar = d_other(arr(i, 1))
ReDim Preserve ar(UBound(ar) + 1)
ar(UBound(ar)) = arr(i, 2)
d_other(arr(i, 1)) = ar
End If
End If
Next
For Each x In d_main.keys
m = m + 1: crr(m, 1) = x
brr = d_main(x)
For i = LBound(brr) To UBound(brr)
x = brr(i)
Call DG(x, crr, d_other, m, 2)
Next
Next
With ActiveSheet
.Range("s2:zz" & Rows.Count).ClearContents
.Range("s2").Resize(m, UBound(crr, 2)).NumberFormat = "@"
.Range("s2").Resize(m, UBound(crr, 2)) = crr
End With
End Sub
Sub DG(x, crr, d_other, m, n)
Dim i, k, brr
crr(m, n) = x
If Not d_other.exists(x) Then
m = m + 1
Else
brr = d_other(x)
For i = LBound(brr) To UBound(brr)
Call DG(brr(i), crr, d_other, m, n + 1)
Next
End If
End Sub
|
|