I have placed this in the Office Automation forum already, but read some very intelligent responses in this forum. So I figured I would give it a try, thinking someone maybe able to help me out.
I am new to this site and have been doing a lot of research to find out about combinations and/or permutations. Not sure which way to go except I am leaning towards combinations.
I found code at http://www.vbforums.com/showthread.p...t=combinations that works great as a starting point for me. I have modified it in Excel (see below) to give me the 1287 combinations of A thru M in a 8 spot variation or bucket (from your 6). I am trying to write or find code that will find all of the 2 pair combinations given a certain number of items (sometimes repeating) that can be placed into multiple 8 spot arrays.
My question is - if you can help, can this be used if the letters repeated and used in as many unique 8 spot buckets? For instance, I have (purely example, would change each time) AAAAAABBBCCDEEEEFFFFFGGGGGGHIJJJKKLLLLMMM (41 items) and 8 spots to fill randomly. Theoretically I can get the most 5 buckets of variations. 41/8 = 5. Knowing A and G have 6 items, they would not be able to use the last item. So now there is 39. That will leave one opening ((5 buckets * 8 spots) - 39) anywhere in the 5 buckets.
The other stipulation is 1 letter per bucket so not to be repeated, nor will the letter be paired with the same letter in any of the other buckets. i.e.
Bucket 1 AB CD EF GH
Bucket 2 AC DE FG HI
Bucket 3 AB KL GH ID AB is a BAD pair, and GH is also a BAD pair because they are together in bucket 1 already.
I am writing this in Excel if that helps. Any help would be appreciated.
Mod code.............
Private Sub Command1_Click()
Dim A() As Variant
A = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M")
MakeUniqueCombinationOfSix A
End Sub
Private Sub MakeUniqueCombinationOfSix(AryOfWhat() As Variant)
On Error GoTo MakeUniqueCombinationOfSixError
Dim NCnt1 As Integer, NCnt2 As Integer, NCnt3 As Integer
Dim NCnt4 As Integer, NCnt5 As Integer, NCnt6 As Integer
Dim NCnt7 As Integer, NCnt8 As Integer
Dim UpperBoundsOfArray As Integer, LowerBoundsOfArray As Integer
UpperBoundsOfArray = UBound(AryOfWhat)
LowerBoundsOfArray = LBound(AryOfWhat)
For NCnt1 = LowerBoundsOfArray To UpperBoundsOfArray
For NCnt2 = NCnt1 + 1 To UpperBoundsOfArray
For NCnt3 = NCnt2 + 1 To UpperBoundsOfArray
For NCnt4 = NCnt3 + 1 To UpperBoundsOfArray
For NCnt5 = NCnt4 + 1 To UpperBoundsOfArray
For NCnt6 = NCnt5 + 1 To UpperBoundsOfArray
For NCnt7 = NCnt6 + 1 To UpperBoundsOfArray
For NCnt8 = NCnt7 + 1 To UpperBoundsOfArray
List1.AddItem AryOfWhat(NCnt1) & "," & AryOfWhat(NCnt2) & "," & _
AryOfWhat(NCnt3) & "," & AryOfWhat(NCnt4) & "," & _
AryOfWhat(NCnt5) & "," & AryOfWhat(NCnt6) & "," & _
AryOfWhat(NCnt7) & "," & AryOfWhat(NCnt8)
Cnt = Cnt + 1
Next NCnt8
Next NCnt7
Next NCnt6
Next NCnt5
Next NCnt4
Next NCnt3
Next NCnt2
Next NCnt1
List1.AddItem Cnt
Exit Sub
MakeUniqueCombinationOfSixError:
MsgBox "MakeUniqueCombinationOfSix " & Err.Number & ":" & Err.Description
End Sub

