+ Reply to Thread
Results 1 to 15 of 15

Lottery: Combinations of 6 numbers in a range of number 1 - 60

  1. #1
    Registered User
    Join Date
    12-04-2014
    Location
    -
    MS-Off Ver
    MS Office 2010
    Posts
    3

    Lottery: Combinations of 6 numbers in a range of number 1 - 60

    I would like to have all combinations of 6 numbers in a range of number 1 - 60. The order of the combinations is not important like: 1-2-3-4-5-6 and 6-5-4-3-2-1. I discovered already that it is not possible only with Excel, so I started with VBA. Does anybody ha a good tutorial to make this kind of calculations, or can anybody help me with this?

    Thank you in advance.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    08-04-2011
    Location
    UK
    MS-Off Ver
    Excel 2021
    Posts
    346

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    you do realise that there are over 50 million combinations, don't you?

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    what would you do with
    36,045,979,200
    results?
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Valued Forum Contributor
    Join Date
    08-04-2011
    Location
    UK
    MS-Off Ver
    Excel 2021
    Posts
    346

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    Quote Originally Posted by martindwilson View Post
    what would you do with
    36,045,979,200
    results?
    just 50,063,860.
    order not required.

  5. #5
    Registered User
    Join Date
    12-04-2014
    Location
    -
    MS-Off Ver
    MS Office 2010
    Posts
    3

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    Strange enough but I do, there are 50063860 combinations. One positive point all the combinations with a sum of 314 max value and a sum of min value 66 are not necessary. I use excel 2010, but I am going to transfer this outcome to access.

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    oops i used permut() yep combin() =50063860

  7. #7
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    Well, as you play lottery, you probably have some spare time.

    In attached file there is a macro which shall (if computer do not say "no!" before it gives you whole list) do this.
    I tested it for smaller samples - 6 numbers out of 20 - 30 - runs fine, for more expect loooong times.
    Of course it could be optimized. But for me it is rather a toy or a kind of "proof of concept" than a real tool so will not spend time on it.

    On my computer (not so special, 3 yrs old laptop):

    For 6 of 20: runtime ca. 7 seconds,
    6 of 30: ca. 280 seconds (yes, almost 5 minutes!)
    You can expect for 6 of 40 some 1 hour.
    I'd do this step to check if it is working.

    If yes - clear the workbook, and let it try for whole 6 of 60.
    It shall finish in some 42 hours But don't blame me if it stops after 39 hrs saying "out of memory" or something like that

    Please Login or Register  to view this content.
    Do not heasitate to let us know of the result (but of course do not post the output workbook - will be huge!).
    Attached Files Attached Files
    Best Regards,

    Kaper

  8. #8
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    if you're putting it into Access then youd be far better off creating the combinations in there rather than spend 2 days waiting for Excel to produce them and then another week to import into Access.












    Just for Access to crash halfway through
    If someone has helped you then please add to their Reputation

  9. #9
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    PJ, Probably you are right. (you have shown no working example, but my experience also says: yes, directly in access shall be better)

    Probably even better - to write from the scratch in some of the quicker programming languages.

    But ... here was a question on excelforum in VBA subforum.
    Moreover I had the code handy from the previous thread from yesterday: http://www.excelforum.com/excel-form...ml#post3930961
    which was again a piece recycled from a thread a week ago: http://www.excelforum.com/excel-prog...ml#post3928668

    So a kind of Maslow's hammer situation :-P

    PS. I just came to the office, where I left "6 out of 50 task" for the night on even older computer. Seems that I was a bit too pesymistic about time needed. It finished after 2 and half hours producing almost 90MB file. Columns up to P (almost) filled up. so almost 16 millions of combinations generated.
    Last edited by Kaper; 12-17-2014 at 07:20 AM.

  10. #10
    Registered User
    Join Date
    12-04-2014
    Location
    -
    MS-Off Ver
    MS Office 2010
    Posts
    3

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    The code works perfect in excel and quite quick also!!! Thanks a lot! Now indeed because of the enormous amount of results I am going to find out where I can storage all this information, maybe in multiple excel tabs and otherwise I need to find a way to export to access.
    But anyhow finally I would like to work in excel (because of my knowledge of Access). I would like to thank you again for your great code and help. If you have any suggestions further please let me know.

  11. #11
    Registered User
    Join Date
    08-25-2017
    Location
    Cambridge
    MS-Off Ver
    2003 Work, 2016 Home
    Posts
    1

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    Hi

    I've tried this code, but it misses out numbers.

    e.g.: with combinations 1-59, I only get 45 million numbers where there should be 45,057,474

    Noticeably 01-02-03-04-05-06 does not exist and many others

    Quote Originally Posted by Kaper View Post
    Well, as you play lottery, you probably have some spare time.

    In attached file there is a macro which shall (if computer do not say "no!" before it gives you whole list) do this.
    I tested it for smaller samples - 6 numbers out of 20 - 30 - runs fine, for more expect loooong times.
    Of course it could be optimized. But for me it is rather a toy or a kind of "proof of concept" than a real tool so will not spend time on it.

    On my computer (not so special, 3 yrs old laptop):

    For 6 of 20: runtime ca. 7 seconds,
    6 of 30: ca. 280 seconds (yes, almost 5 minutes!)
    You can expect for 6 of 40 some 1 hour.
    I'd do this step to check if it is working.

    If yes - clear the workbook, and let it try for whole 6 of 60.
    It shall finish in some 42 hours But don't blame me if it stops after 39 hrs saying "out of memory" or something like that

    Please Login or Register  to view this content.
    Do not heasitate to let us know of the result (but of course do not post the output workbook - will be huge!).

  12. #12
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    Hi CecilP,

    1) administrative: Please investt some time and read (then follow) our https://www.excelforum.com/forum-rul...rum-rules.html
    You already broke rule 2 and 12

    2) merit: Solution was tailored to specific needs. You may try to comment out lines with genearted sum limits:

    Please Login or Register  to view this content.

  13. #13
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    Quote Originally Posted by CecilP View Post
    Hi
    Welcome to the Forum! Please review our rules, then start a new thread with your question. Thanks.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  14. #14
    Registered User
    Join Date
    01-02-2020
    Location
    Algeria
    MS-Off Ver
    2010 Standar
    Posts
    1

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    Hello Dude, i'm looking for the same things, i want to generate all combinations of 6 numbers among 1-60, i just know that there is 50 063 860 combinations possible; i have more than 2000 combinations which i have to filter ; so did you find the solution how to generate all this combinations in Excel ? thank you

  15. #15
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Lottery: Combinations of 6 numbers in a range of number 1 - 60

    Please read and follow forum rules.
    https://www.excelforum.com/forum-rul...rum-rules.html
    Follow all of them.
    This time focus especially on rule 4.

    You will not receive any further answers in this thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] entering combinations of numbers in 3 cells from specifed range
    By net.rider in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-23-2012, 04:04 AM
  2. [SOLVED] Listing combinations of 6 numbers from a range.
    By Prit50 in forum Excel General
    Replies: 9
    Last Post: 09-10-2012, 08:11 AM
  3. Replies: 1
    Last Post: 02-03-2012, 06:25 AM
  4. Replies: 10
    Last Post: 01-24-2012, 08:58 PM
  5. [SOLVED] Displaying all combinations of a range of numbers
    By Mally in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-06-2005, 03:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1