Thread: Loop & Count
View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Loop & Count

Sub CountDoubles()
Dim s As String, arr As Variant
Dim i As Long, j As Long
Dim n As Long
Set dic = CreateObject("Scripting.Dictionary")
For Each cell In Range("G13:G17")
arr = cell.Resize(1, 6).Value
For i = 1 To 5
For j = i + 1 To 6
s = arr(1, i) & "," & arr(1, j)
If Not dic.Exists(s) Then
dic.Add s, Nothing
n = n + 1
End If
Next
Next
Next
MsgBox n
End Sub


--
Regards,
Tom Ogilvy

"Paul Black" wrote in message
ps.com...
Thanks for the Reply Tom,

I think your Explanation is Correct. I am just having Trouble Trying to
Explain Exactly what I want to Achieve.
There are 20 Triples for Each 6 Number Combination.
So for the First Triple in the First Combination there are Doubles of 1
2, 1 4 & 2 4. Now 1 2 is Also Included in the First Triple in the
Second Combination 1 2 5. The Double 1 2 Only Needs to be Counted the
Once though. The Code Needs to Count Unique Doubles in Each Triple in
All the Combinations.

Thanks Very Much in Advance.
All the Best.
Paul

Tom Ogilvy wrote:
I am not sure I understand the rules.

From your description, it sounds like you need to loop throught the data,
row at a time.

For each row, generate every combination of two values from 6 and put
them
in the dictionary
when done, count the items in the dictionary.

every combination of two has to be an subset of a combination of 3.

Tell me where I don't understand the rules.

--
Regards,
Tom Ogilvy

"Paul Black" wrote in message
...
Thanks for the Reply Tom,

Would you be Able to Assist me in Adapting the Code I Posted to
Calculate the 2 if 3 Scenario Please. I Assume ( Probably Wrongly )
that
it will Mean Adding a If...Then Statement or Such like to Count and
Hold
the Total.
Thanks Very Much in Advance.

All the Best.
Paul


*** Sent via Developersdex http://www.developersdex.com ***