Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Newsgroup Archive
Excel Newsgroups
Excel Programming
setting up number combinations
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Joel, post: 6271272"] Below is code I wrote for somebody else earlier this week. Modify these two line as necessary 'you can make instring as long or short as you want. You can put string in the array instead of number. 'for 6 players InStrings = Array(1, 2, 3, 4, 5, 6) 'for 10 players InStrings = Array(1, 2, 3, 4, 5, 6,7,8,9,10) modify for size of team or number of teams playing together ComboLen = 2 Public InStrings Public combo Public RowCount Public ComboLen Sub combinations() InStrings = Array(1, 2, 3, 4, 5, 6) Length = UBound(InStrings) + 1 Level = 1 RowCount = 1 ComboLen = 2 ReDim combo(ComboLen) Position = 0 Call recursive(Level, Position) End Sub Sub recursive(ByVal Level As Integer, ByVal Position As Integer) Length = UBound(InStrings) + 1 For i = Position To (Length - 1) 'for combinations check if item already entered found = False For j = 0 To (Level - 2) 'combo is a count of the combinations,not the actual data '123 '124 '125 '234 '235 '245 '345 'data is actually in InStrings If combo(j) = i Then found = True Exit For End If Next j If found = False Then combo(Level - 1) = i If Level = ComboLen Then For j = 0 To (ComboLen - 1) If j = 0 Then ComboString = InStrings(combo(j)) Else ComboString = ComboString & "," & InStrings(combo(j)) End If Next j Sheets("Sheet2").Range("A" & RowCount) = ComboString RowCount = RowCount + 1 Else Call recursive(Level + 1, i) End If End If Next i End Sub [/QUOTE]
Verification
Post reply
Forums
Archive
Newsgroup Archive
Excel Newsgroups
Excel Programming
setting up number combinations
Top