Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through Combinations and Keep a Count Paul Black Excel Programming 0 October 10th 05 02:32 PM
count rownumbers in loop TUNGANA KURMA RAJU Excel Discussion (Misc queries) 9 October 3rd 05 09:29 AM
loop count TUNGANA KURMA RAJU Excel Discussion (Misc queries) 2 October 1st 05 04:54 AM
End loop macro with count Jason C. Excel Programming 1 July 16th 03 01:21 PM


All times are GMT +1. The time now is 07:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"