Loop & Count
Hi Tom,
The Code I have is as Follows.
Is there Another Way to Write the Following Code ( without Using the
Scripting Dictonary ) that Doesn't Use the Scripting Dictionary Please
so I can Better Understand :-
Code:
Sub test_5()
Dim a, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
a = Range("g13").CurrentRegion.Value
For i = 1 To UBound(a, 1)
For ii = 1 To 2
For iii = ii + 1 To 3
For iv = iii + 1 To 4
For v = iv + 1 To 5
For vi = v + 1 To 6
z = a(i, ii) & "," & a(i, iii) & a(i, iv) &
a(i, v) & a(i, vi)
If Not dic.exists(z) Then
dic.Add z, Nothing
n = n + 1
End If
Next vi, v, iv, iii, ii, i
Set dic = Nothing
Range("O16") = n
End Sub
Thanks in Advance.
All the Best.
Paul
Tom Ogilvy wrote:
how to write a vba procedure that counts the number of unique 2 of 3
combinations in the data set in G13:L17
--
Regards,
Tom Ogilvy
"JLGWhiz" wrote:
What is the question?
"Paul Black" wrote:
Hi Everyone,
I will Try and Explain this Clearly for a 2 if 3 Scenario.
If we have the Following 6 Number Combinations in Cells G13:L17 ...
1 2 3 4 5 6
1 2 3 5 6 8
1 2 3 5 7 8
1 2 3 6 7 8
1 2 4 7 8 9
.... and Wanted to Calculate How Many 2 Number Combinations are Covered
if we Match 3 Numbers.
If we took the Set of Numbers 1 2 3 for Example, the Numbers 1 2 Appear
in 5 Combinations, but we Only Want it Counted Once. So in Theory, the
Macro would Only Need to Check the First Combination to Satisfy if the
Numbers 1 2 are Covered. The Next 2 if 3 Scenario will be 1 3, in this
Case there are 4 Combinations with the Numbers 1 3 in the Set 1 2 3,
and Again, the Macro would Only Need to Check the First Combination to
Satisfy if the Numbers 1 3 are Covered. Obviously the Numbers 1 4, 1 5,
1 6, 1 7, 1 8, 1 9, 2 4, 2 5 etc are Not included in the Set 1 2 3, but
are Included in Other Sets of 3 Numbers. For Example, 1 4 will be
Included in the Set 1 3 4. If Any of the 3 Numbers Sets doesn't Include
Any of the 2 Number Combinations that can be Made with Numbers 1 to 9
then that 2 Number Combination is Not Covered and therfore Not Included
in the 2 if 3 Total.
This will Continue for All the Sets of 3 Numbers that can be Made from
the Combinations, taken 1 Combination at a Time. Basically, I want a
Total of the 2 Number Combinations Covered if we Use Sets of 3 Numbers.
Any Help will be Greatly Appreciated.
All the Best.
Paul
|