Sub test()
Dim i As Integer
count_6 = Application.WorksheetFunction.CountIf(Range("A1:L1"), 6)
For i = 1 To count_6
Cells(3, i) = 6
Next i
End Sub
[COLOR=Navy]Sub[/COLOR] MG30Jul38
[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
[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
[COLOR=Navy]Dim[/COLOR] Dic [COLOR=Navy]As[/COLOR] Object, K [COLOR=Navy]As[/COLOR] Variant, s [COLOR=Navy]As[/COLOR] [COLOR=Navy]String[/COLOR]
[COLOR=Navy]Set[/COLOR] Rng = Range("A1:L1")
[COLOR=Navy]Set[/COLOR] Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng
[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
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), ",")
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)) = 11 [COLOR=Navy]Then[/COLOR]
[COLOR=Navy]For[/COLOR] n = 1 To UBound(ray)
[COLOR=Navy]With[/COLOR] Range("A" & n).Offset(1)
.NumberFormat = "@": Sp = Split(ray(n), ","): s = ""
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] R [COLOR=Navy]In[/COLOR] Split(ray(n), ",")
s = s & "," & Dic.Item(Val(R))
[COLOR=Navy]Next[/COLOR] R
.Value = Mid(s, 2)
[COLOR=Navy]End[/COLOR] With
[COLOR=Navy]Next[/COLOR] n
[COLOR=Navy]Exit[/COLOR] [COLOR=Navy]Sub[/COLOR]
[COLOR=Navy]End[/COLOR] If
Loop
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
[COLOR="Navy"]Sub[/COLOR] MG31Jul32
[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, p [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
[COLOR="Navy"]Dim[/COLOR] Dic [COLOR="Navy"]As[/COLOR] Object, K [COLOR="Navy"]As[/COLOR] Variant, s [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range("A1:L1")
[COLOR="Navy"]Set[/COLOR] Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
[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
ReDim ray(1 To Dic.Count)
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] Dic.keys: p = p + 1: ray(p) = 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), ",")
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)) = 11 [COLOR="Navy"]Then[/COLOR]
[COLOR="Navy"]For[/COLOR] n = 1 To UBound(ray)
[COLOR="Navy"]With[/COLOR] Range("A" & n).Offset(1)
.NumberFormat = "@": Sp = Split(ray(n), ","): s = ""
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] R [COLOR="Navy"]In[/COLOR] Split(ray(n), ",")
s = s & "," & Dic.Item(Val(R))
[COLOR="Navy"]Next[/COLOR] R
.Value = Mid(s, 2)
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Sub[/COLOR]
[COLOR="Navy"]End[/COLOR] If
Loop
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]