[COLOR="Navy"]Sub[/COLOR] MG30Oct45
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, Temp [COLOR="Navy"]As[/COLOR] Variant, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] nn [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] ray [COLOR="Navy"]As[/COLOR] Variant, S [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Fst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Fin [COLOR="Navy"]As[/COLOR] Variant, oFst [COLOR="Navy"]As[/COLOR] Variant, nLst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] oTem [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] nFst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] r [COLOR="Navy"]As[/COLOR] Variant, Sp [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] Str [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] nST [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] sT [COLOR="Navy"]As[/COLOR] Variant, nStr [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Dic [COLOR="Navy"]As[/COLOR] Object, K [COLOR="Navy"]As[/COLOR] Variant, nDn [COLOR="Navy"]As[/COLOR] Range, AcRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dic2 [COLOR="Navy"]As[/COLOR] Object, num [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
[COLOR="Navy"]Set[/COLOR] Dic2 = CreateObject("scripting.dictionary")
Dic2.CompareMode = vbTextCompare
[COLOR="Navy"]With[/COLOR] Sheets("Sheet1")
[COLOR="Navy"]Set[/COLOR] Rng = .Range(.Range("A1"), .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] nDn [COLOR="Navy"]In[/COLOR] Rng
Dic.RemoveAll
[COLOR="Navy"]Set[/COLOR] AcRng = nDn.Resize(, 6)
n = 0
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] AcRng
[COLOR="Navy"]If[/COLOR] Not Dic.exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
n = n + 1
Dic.Add n, Dn.Value
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
c = 2
S = 0
ReDim ray(1 To Dic.Count)
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] Dic.keys: S = S + 1: ray(S) = K
[COLOR="Navy"]Next[/COLOR] K
Str = Join(Application.Transpose(Application.Transpose(Dic.keys)), ",")
oTem = ray: nLst = Dic.Count
[COLOR="Navy"]Do[/COLOR] Until ray(1) = Str
Temp = ray: c = 0
[COLOR="Navy"]For[/COLOR] nn = 1 To UBound(Temp) - 1
sT = Split(Temp(nn + 1), ",") '[COLOR="Green"][B]+1[/B][/COLOR]
nST = IIf(UBound(sT) = 0, Temp(nn + 1), sT(UBound(sT)))
oFst = Split(Temp(nn), ",")
nFst = IIf(UBound(oFst) = 0, Temp(nn), oFst(UBound(oFst)))
[COLOR="Navy"]For[/COLOR] n = nST To nLst
[COLOR="Navy"]If[/COLOR] oTem(n) > nFst [COLOR="Navy"]Then[/COLOR]
c = c + 1
ReDim Preserve ray(1 To c)
ray(c) = Temp(nn) & "," & oTem(n)
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]Next[/COLOR] nn
[COLOR="Navy"]If[/COLOR] Len(ray(1)) = 5 [COLOR="Navy"]Then[/COLOR]
[COLOR="Navy"]For[/COLOR] n = 1 To UBound(ray)
[COLOR="Navy"]With[/COLOR] Range("A" & n).Offset(, 10)
.NumberFormat = "@": Sp = Split(ray(n), ","): nStr = ""
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] r [COLOR="Navy"]In[/COLOR] Split(ray(n), ",")
nStr = nStr & "," & Dic.Item(Val(r))
[COLOR="Navy"]Next[/COLOR] r
'[COLOR="Green"][B].Value = Mid(nStr, 2)[/B][/COLOR]
[COLOR="Navy"]If[/COLOR] Not Dic2.exists(Mid(nStr, 2)) [COLOR="Navy"]Then[/COLOR]
Dic2.Add Mid(nStr, 2), 1
[COLOR="Navy"]Else[/COLOR]
Dic2(Mid(nStr, 2)) = Dic2(Mid(nStr, 2)) + 1
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Loop[/COLOR]
[COLOR="Navy"]Next[/COLOR] nDn
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] Dic2.keys
[COLOR="Navy"]If[/COLOR] Dic2(K) > num [COLOR="Navy"]Then[/COLOR]
Temp = K
num = Dic2(K)
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]With[/COLOR] Sheets("Sheet2")
.Range("A1") = Temp
.Range("B1") = num
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]