Sub blah5()
Set d = CreateObject("Scripting.dictionary")
Set cll = Range("A1")
Dim X()
Do
xx = Split(Application.Trim(cll.Value), " ")
If UBound(xx) = 5 Then
For I = 0 To 1
For j = I + 1 To 2
For k = j + 1 To 3
For l = k + 1 To 4
For m = l + 1 To 5
fivesome = Format(xx(I), "00") & "," & Format(xx(j), "00") & "," & Format(xx(k), "00") & "," & Format(xx(l), "00") & "," & Format(xx(m), "00")
Smaller = Application.Min(xx(I), xx(j), xx(k), xx(l), xx(m))
Middle = Application.Median(xx(I), xx(j), xx(k), xx(l), xx(m))
Larger = Application.Max(xx(I), xx(j), xx(k), xx(l), xx(m))
fivesome = Replace(Replace(Replace(Replace(Replace("," & fivesome & ",", Format(Smaller, "00"), ""), Format(Larger, "00"), ""), Format(Middle, "00"), ""), ",,", ","), ",,", ",")
inner = Split(Mid(fivesome, 2, Len(fivesome) - 2), ",")
Firstmiddle = Application.Min(inner(0), inner(1))
Secondmiddle = Application.Max(inner(0), inner(1))
thisfivesome = Format(Smaller, "00") & "," & Format(Firstmiddle, "00") & "," & Format(Middle, "00") & "," & Format(Secondmiddle, "00") & "," & Format(Larger, "00")
If d.Exists(thisfivesome) Then
d.Item(thisfivesome) = d.Item(thisfivesome) + 1
Else
d.Add thisfivesome, 1
End If
Next m
Next l
Next k
Next j
Next I
End If
Set cll = cll.Offset(1)
Loop Until IsEmpty(cll)
ReDim X(1 To d.Count, 1 To 2)
I = 0
For Each p In d.Keys
I = I + 1
X(I, 1) = p
X(I, 2) = d.Item(p)
Next p
Set rngResults = Range("C2").Resize(d.Count, 2)
rngResults.Value = X
With ActiveSheet.Sort
.SortFields.Clear
.SortFields.Add Key:=rngResults.Columns(2), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.SortFields.Add Key:=rngResults.Columns(1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange rngResults
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
For 6 - note that you don't have to use loops at all - you are just checking if all are repeated. and moreover - they are already sorted so code is shorter again.
Sub blah6()
Set d = CreateObject("Scripting.dictionary")
Set cll = Range("A1")
Dim X()
Do
xx = Split(Application.Trim(cll.Value), " ")
If UBound(xx) = 5 Then
sixsome = ""
For i = 0 To 5
sixsome = sixsome & "," & Format(xx(i), "00")
Next i
sixsome = Mid(sixsome, 2)
If d.Exists(sixsome) Then
d.Item(sixsome) = d.Item(sixsome) + 1
Else
d.Add sixsome, 1
End If
End If
Set cll = cll.Offset(1)
Loop Until IsEmpty(cll)
ReDim X(1 To d.Count, 1 To 2)
i = 0
For Each p In d.Keys
i = i + 1
X(i, 1) = p
X(i, 2) = d.Item(p)
Next p
Set rngResults = Range("C2").Resize(d.Count, 2)
rngResults.Value = X
With ActiveSheet.Sort
.SortFields.Clear
.SortFields.Add Key:=rngResults.Columns(2), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.SortFields.Add Key:=rngResults.Columns(1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange rngResults
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Bookmarks