Easy way to get 15 free YouTube views, likes and subscribers
Get Free YouTube Subscribers, Views and Likes

Excel - Generating All Possible Lottery Combinations in Excel - Step by Step Tutorial - Episode 2441

Follow
MrExcel.com

Microsoft Excel Tutorial: List all lottery combinations.

Download the workbook with the VBA Code: https://www.mrexcel.com/youtube/vpqmI...

Welcome to episode 2441 of the MrExcel Netcast, where we will be discussing how to generate all possible lottery combinations in Excel. This is a question sent in by one of our viewers, Reid, who wants to find all combinations of six numbers from 1 to 44. As we all know, winning the lottery is not an easy feat, and with 44 numbers to choose from, there are a staggering 7,059,052 possible combinations. This is where Excel comes in handy, as it can help us generate a list of all these combinations.

The first challenge we face is that Excel only has 1,048,576 rows, which is not enough to accommodate all the combinations. To overcome this, we will be using VBA (Visual Basic for Applications) to automate the process. If you are new to VBA, don't worry, I will guide you through the steps. First, we need to enable the Developer tab in Excel by rightclicking and selecting "Customize the Ribbon". Then, we will insert a new module and paste the code that will be provided in the YouTube description.

The code, called "ListThemAll", will start in column A and row 1, and will have a counter to keep track of the number of combinations. Once we reach the maximum number of rows in the spreadsheet, which is determined by the "Rows.Count" function, we will move on to the next column. To speed up the process, we will turn off screen updating. Since the digits cannot be arranged in sequence, we know that the first number chosen can't be higher than 39. Therefore, we will use a loop to generate all possible combinations, starting with 1 to 39 for the first number, and then incrementing the second number by 1 each time. This process will continue until we reach the last number, which will be 44.

As the code runs, it will save the workbook every 25,000 combinations, and we can monitor its progress in Windows Explorer. Once it finishes, we will have a list of all 7,059,052 lottery combinations in Excel. Of course, this code can be adapted for different lottery systems, such as Powerball, where there are five balls from 1 to 69 and a Powerball from 1 to 26. If you want to learn more about macros and VBA, check out our book "Excel 2016 VBA and Macros" written by Tracy and myself.

Thank you for watching this episode of the MrExcel Netcast. If you found this tutorial helpful, please like, subscribe, and ring the bell to be notified of our future videos. Also, feel free to leave any questions or comments in the YouTube comments section below. I want to thank Reid for sending in this question, and I hope this tutorial has helped you in generating all possible lottery combinations in Excel. See you next time for another netcast from MrExcel. Hit it, Nancy!

Buy Bill Jelen's latest Excel book: https://www.mrexcel.com/products/latest/'>https://www.mrexcel.com/products/latest/

You can help my channel by clicking Like or commenting below: https://www.mrexcel.com/likemrexcel...


Table of Contents
(0:00) Problem Statement: Use Excel to generate all lottery combinations
(0:35) Use COMBIN function to figure out how many combinations
(1:03) Changing Macro Security
(1:17) Add Developer tab in Excel
(1:35) Insert a VBA module and paste VBA code
(1:55) Explaining the VBA
(3:20) Saving the workbook every 25K records
(4:10) Run the macro
(5:09) Customizing for your lottery
(5:32) Buy the VBA book
(5:51) Clicking Like really helps the algorithm

#excel #microsoft #microsoftexcel #exceltutorial #exceltips #exceltricks #excelmvp #freeclass #freecourse #freeclasses #excelclasses #microsoftmvp #walkthrough #evergreen #spreadsheetskills #analytics #analysis #dataanalysis #dataanalytics #mrexcel #spreadsheets #spreadsheet #excelhelp #accounting #tutorial

This video answers these common search terms:
Concatenate in Excel
Developer tab in Excel
Excel macros
Excel Project Explorer
Excel rows limit
Excel screen updating
Excel VBA
Learn Excel
Lottery combinations
Powerball lottery

Join the MrExcel Message Board discussion about this video at https://www.mrexcel.com/board/threads...

For my video course to learn VBA Macros: https://www.pearson.com/uk/educators/...

Buy Bill Jelen's latest Excel book: https://www.mrexcel.com/products/latest/'>https://www.mrexcel.com/products/latest/

Reid would like to list all 6number combinations of the numbers 1 to 44. For example, 123456, 123457, and so on up to 394041424344. The first thing to realize is that all lottery combinations are a lot of numbers. Over 7 million possibilities according to the COMBIN function in Excel. (For Power Ball, there are 292 million combinations!). Listing all combinations will be difficult because Excel only includes 1,048,576 rows.
In this video, I show how to enable Macros in your version of Excel and then the macro code to list all possible combinations.

posted by dojitevvr