all lottery combinations 1 - 49

damainman

New Member
Joined
Feb 10, 2008
Messages
16
i need excel to output all lottery combinations. the numbers are from 1-49 from which 6 numbers are drawn. i do realise the number of combinations are 13983816. i want the 6 numbers drawn to be in different cells across 6 different columns. so the 1st 6 numbers are in a1, b1, c1, d1, e1, f1. obviously excel 2003 has 65536 rows and so the formula/vb code should carry on onto a new worksheet or ideally a new workbook. its ideal in a new workbook so not to end up with a single huge 10gig file, but on several worksheets in 1 workbook is fine.

i have been trying to do this myself for a while now with no success. any help would be great. from what i understand; this is a bit of a challenge i know.
 
Ran in 2007 and it filled 13 sheets, with 352,328 lines in sheet 14 (took about 90 minutes, 324mb file...!)

13 * 1,048,576 + 352,328 = 13,983,816

So if your maths was right to begin with, I'd say that's job done

Code:
Sub allLottery()
    Dim x As Long
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
    End With
    x = doTheLott("", 1, 1)
    With Application
        .StatusBar = False
        .ScreenUpdating = True
        .Calculation = xlCalculationAutomatic
    End With
    ActiveWorkbook.Save
End Sub

Function doTheLott(ByVal xStr As String, r As Long, a As Integer) As Long
    Dim xArr As Variant, i As Integer
    xArr = Split(Trim(xStr), " ")
    If UBound(xArr) = 5 Then
        Cells(r, 1).Resize(1, 6).Value = xArr
        r = r + 1
        If r > Rows.Count Then
            Sheets.Add
            ActiveWorkbook.Save
            r = 1
        End If
    Else
        For i = a To 49
            j = Format(i, "00")
            If InStr(xStr, j) = 0 Then
                r = doTheLott(xStr & j & " ", r, i)
            End If
        Next
    End If
    doTheLott = r
End Function
Mind you, I wouldn't try running it on 2003 again...
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
The ability to analyze nearly 14 million numbers especially when scattered across multiple worksheets / workbooks is close to non-existent! Why generate the numbers when you really won't be able to do anything with them?
i need excel to output all lottery combinations. the numbers are from 1-49 from which 6 numbers are drawn. i do realise the number of combinations are 13983816. i want the 6 numbers drawn to be in different cells across 6 different columns. so the 1st 6 numbers are in a1, b1, c1, d1, e1, f1. obviously excel 2003 has 65536 rows and so the formula/vb code should carry on onto a new worksheet or ideally a new workbook. its ideal in a new workbook so not to end up with a single huge 10gig file, but on several worksheets in 1 workbook is fine.

i have been trying to do this myself for a while now with no success. any help would be great. from what i understand; this is a bit of a challenge i know.
 
Upvote 0
The ability to analyze nearly 14 million numbers especially when scattered across multiple worksheets / workbooks is close to non-existent! Why generate the numbers when you really won't be able to do anything with them?
If doing it is so pointless, then so is asking why...:laugh:

Besides which, it was fun.
 
Upvote 0
I just laughed out loud reading this, i run that many things at one time that if i had run that code i think the neigbourhood would black out :)

Yes it's a pointless excercise, no one really has the time to analyse all those entries. Wouldn't you be better off importing all the latest draws and analysing the frequency and mode of the draws?
 
Upvote 0
If it's any good to you i can get ALL the combinations on one sheet 6 numbers per cell no duplications?
Simon

I think I could probably rewrite mine to do the same - it starts off as a string in any case.

I'm off to calculate pi to googol^googol places now....
 
Upvote 0
Hey guys,

Thought I'd just throw in my 2 cents worth but based on the COMBIN function, there should be 8,145,060 possibilities i.e. =COMBIN(45,6) so I'd say Weaver's solution is out somehow (perhaps due the same numbers being drawn but in a different order).

Cheers,

Robert
 
Upvote 0
Trebor - I've often heard it said there's a 1 in 14,000,000 chance of winning the lottery, so I figured the original estimate was ball park. I just tried =COMBIN(49,6) and got 13,983,816.

PS - great function, never spotted it before.

PPS - where's the emoticon for 'Victory Dance'?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top