Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub CountDoubles()
Dim s As String, arr As Variant Dim i As Long, j As Long Dim n As Long Dim v(1 To 120, 1 To 3) As Long Dim v1(1 To 120) As Long l = 0 For i = 1 To 8 For j = i + 1 To 9 For k = j + 1 To 10 l = l + 1 v(l, 1) = i v(l, 2) = j v(l, 3) = k Next Next Next For l = 1 To 120 v1(l) = 0 Next For Each cell In Range("G13:G17") arr = cell.Resize(1, 6).Value For l = 1 To 120 If v1(l) = 0 Then cnt = 0 For i = 1 To 3 For j = 1 To 6 If arr(1, j) = v(l, i) Then cnt = cnt + 1 Next Next If cnt = 2 Then v1(l) = 1 n = n + 1 End If End If Next l Next cell MsgBox n End Sub gave me what I expected, but for your example, I expected 60, not 80. -- Regards, Tom Ogilvy "Paul Black" wrote in message ps.com... Hi Tom, I Hope your Year is going Well. Have you had Time to have a Look through my above Post yet?. Thanks in Advance. All the Best. Paul Paul Black wrote: Hi Tom, Thanks for the Response. Unfortunately the Code did Not do as I Expected. This is Due to MY Bad Explanation of what I would like. I think the Following Explanation is Better Suited and will Hopefully bring it into Focus. Lets Assume that we have 6 Numbers in Each Combination ... 01 02 03 08 09 10 etc etc ... for Example. If we just Concentrate on the 2 if 3 Scenario, the Code Needs to do the Following :- Because the Maximum Number in the Combination in this Case is 10, we Need to Calculate and Store the 120 Combinations ( =COMBIN(10,3) = 120 ) Produced for 3 Numbers from 10 Numbers. I Assume this will be Stored in the Scripting Dictionary. Then Loop through Each Triple Stored in the Scripting Dictionary and Count How Many of those 120 Triples have Exactly 2 Numbers in Our Combination of 01 02 03 08 09 10. The Answer in this Case for Combination 01 02 03 08 09 10 should Equal 80. The Macro Basically Needs to Loop through Every 3 Number Combination in the Scripting Dictionary and Compare it to Each Individual Combination in Our Wheel. If Exactly 2 Numbers in Any of Our Wheel Combinations Match Exactly 2 Numbers in Any of the 3 Number Combinations in the Scripting Dictionary then that is Counted and the Macro Moves on to the Next Combination in the Scripting Dictionary etc. Or the Macro could Loop through the Wheel and Compare it to the Scripting Dictionary. Thanks Very Much in Advance. All the Best. Paul *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Loop through Combinations and Keep a Count | Excel Programming | |||
count rownumbers in loop | Excel Discussion (Misc queries) | |||
loop count | Excel Discussion (Misc queries) | |||
End loop macro with count | Excel Programming |