[COLOR="Navy"]Sub[/COLOR] MG02Mar50
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Q [COLOR="Navy"]As[/COLOR] Variant, K [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] I, J, Col1 [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Col2 [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
[COLOR="Navy"]If[/COLOR] Not .Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
ReDim Ray(1 To 2, 1 To 1)
Ray(1, 1) = Dn.Offset(, 1).Value
Ray(2, 1) = Dn.Offset(, 2).Value
.Add Dn.Value, Ray
[COLOR="Navy"]Else[/COLOR]
Q = .Item(Dn.Value)
ReDim Preserve Q(1 To 2, 1 To UBound(Q, 2) + 1)
Q(1, UBound(Q, 2)) = Dn.Offset(, 1).Value
Q(2, UBound(Q, 2)) = Dn.Offset(, 2).Value
.Item(Dn.Value) = Q
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
Ac = 7
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .keys
Q = .Item(K)
[COLOR="Navy"]For[/COLOR] I = 1 To UBound(Q, 2)
[COLOR="Navy"]For[/COLOR] J = I To UBound(Q, 2)
[COLOR="Navy"]If[/COLOR] Val(Q(2, J)) < Val(Q(2, I)) [COLOR="Navy"]Then[/COLOR]
Col1 = Q(1, I)
Col2 = Q(2, I)
Q(1, I) = Q(1, J)
Q(2, I) = Q(2, J)
Q(1, J) = Col1
Q(2, J) = Col2
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] J
[COLOR="Navy"]Next[/COLOR] I
.Item(K) = Q
Ac = Ac + 1
Cells(1, Ac) = K
Cells(2, Ac).Resize(UBound(.Item(K), 2), 1) = Application.Index(Application.Transpose(.Item(K)), _
Evaluate("Row(1:" & UBound(.Item(K), 2) & ")"), 0)
[COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]