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 am also not sure if I should hijack this thread, but since you have the best example i am going to try, but will post a new one as well.

VB5prgrmr,
Your code works great as a starting point for me, so this is wonderful, easy to understand and very quick. I have modified it (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.............
vb Code:
  1. Private Sub Command1_Click()
  2.  
  3. Dim A() As Variant
  4.  
  5. A = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M")
  6.  
  7. MakeUniqueCombinationOfSix A
  8.  
  9. End Sub
  10.  
  11. Private Sub MakeUniqueCombinationOfSix(AryOfWhat() As Variant)
  12.  
  13. On Error GoTo MakeUniqueCombinationOfSixError
  14.  
  15. Dim NCnt1 As Integer, NCnt2 As Integer, NCnt3 As Integer
  16. Dim NCnt4 As Integer, NCnt5 As Integer, NCnt6 As Integer
  17. Dim NCnt7 As Integer, NCnt8 As Integer
  18. Dim UpperBoundsOfArray As Integer, LowerBoundsOfArray As Integer
  19.  
  20. UpperBoundsOfArray = UBound(AryOfWhat)
  21. LowerBoundsOfArray = LBound(AryOfWhat)
  22.  
  23. For NCnt1 = LowerBoundsOfArray To UpperBoundsOfArray
  24.   For NCnt2 = NCnt1 + 1 To UpperBoundsOfArray
  25.     For NCnt3 = NCnt2 + 1 To UpperBoundsOfArray
  26.       For NCnt4 = NCnt3 + 1 To UpperBoundsOfArray
  27.         For NCnt5 = NCnt4 + 1 To UpperBoundsOfArray
  28.           For NCnt6 = NCnt5 + 1 To UpperBoundsOfArray
  29.             For NCnt7 = NCnt6 + 1 To UpperBoundsOfArray
  30.                 For NCnt8 = NCnt7 + 1 To UpperBoundsOfArray
  31.                     List1.AddItem AryOfWhat(NCnt1) & "," & AryOfWhat(NCnt2) & "," & _
  32.                                   AryOfWhat(NCnt3) & "," & AryOfWhat(NCnt4) & "," & _
  33.                                   AryOfWhat(NCnt5) & "," & AryOfWhat(NCnt6) & "," & _
  34.                                   AryOfWhat(NCnt7) & "," & AryOfWhat(NCnt8)
  35.                                   Cnt = Cnt + 1
  36.                 Next NCnt8
  37.             Next NCnt7
  38.           Next NCnt6
  39.         Next NCnt5
  40.       Next NCnt4
  41.     Next NCnt3
  42.   Next NCnt2
  43. Next NCnt1
  44. List1.AddItem Cnt
  45. Exit Sub
  46. MakeUniqueCombinationOfSixError:
  47.  
  48. MsgBox "MakeUniqueCombinationOfSix " & Err.Number & ":" & Err.Description
  49.  
  50. End Sub