Generating combinations
946ottol
Before spending any money on programs, you may want to try the following macro in Excel:
Code:
Option Explicit
Option Base 1
Dim A As Integer, B As Integer, C As Integer, D As Integer, E As Integer, F As Integer
Dim nNb() As Integer, I As Integer, J As Double
Sub GetCombin()
' Program to generate 6-number combinations
Application.ScreenUpdating = False
ReDim nNb(20)
Range("A1").Select
I = 1
' Allow up to 20 numbers starting in A1 and descending
Do Until I = 21
If ActiveCell.Offset(I - 1, 0) = "" Then Exit Do
nNb(I) = ActiveCell.Offset(I - 1, 0).Value
I = I + 1
Loop
ReDim Preserve nNb(I)
I = I - 1
J = 1
' Place combinations in columns C to H starting at row 2
For A = 1 To I - 5
For B = A + 1 To I - 4
For C = B + 1 To I - 3
For D = C + 1 To I - 2
For E = D + 1 To I - 1
For F = E + 1 To I
ActiveCell.Offset(J, 2).Value = nNb(A)
ActiveCell.Offset(J, 3).Value = nNb(B)
ActiveCell.Offset(J, 4).Value = nNb(C)
ActiveCell.Offset(J, 5).Value = nNb(D)
ActiveCell.Offset(J, 6).Value = nNb(E)
ActiveCell.Offset(J, 7).Value = nNb(F)
J = J + 1
Next F
Next E
Next D
Next C
Next B
Next A
Application.ScreenUpdating = True
End Sub
Instructions:
- Starting in A1 and down, place up to 20 numbers you want to use in 6-number combinations.
- Start the macro and bingo.
- Starting in C2 to H2 and down, you will get your all your combinations fairly quickly depending on your computer and how many numbers you choose.
- Make cosmetic changes as you want (headings, column widths, etc.).
- Filter, erase, choose or do what you want with those combinations
Comments:
- Why a limit of 20 numbers? This will give you 38,760 combinations to select from. Enough I believe but also because with more numbers, it would soon need another 6 columns to place combinations and this is feasible but more complicated. With 22 numbers, you can get 74,613 combinations, more than the 65,536 lines in Excel. But I have one macro that places all 13,983,816 combinations in a single sheet.
- There is no guarantee that this will help you win big but enjoy yourself. For myself, the fun was creating the macro.