Excel VBA - Create Sets from Lottery Game - Right Digits Only

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
961
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hello everyone,

I'm looking for VBA code that will create only the sets from a lottery game such as a 5/39 game

For example:

Set = 01 - 02 - 03 - 04 - 05
Right digit set = 1 - 2 - 3 - 4 - 5

Set 35 - 36 - 37 - 38 - 39
Right digit set = 5 - 6 - 7 - 8 - 9

Eliminate any duplicate sets if possible.

Thank you.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
A followup question:

How do I continue the calculations past 1,048,576 rows until caculations comple?


The following code gives me an error where it stops at cell "A1048576"

Thanks in advance!!

Option Explicit

Dim A As Integer, B As Integer, C As Integer, D As Integer, E As Integer
Dim N As Long, nMinA As Integer, nMaxE As Integer

Sub List_5x69Comb()

' Macro to list combinations in an Excel sheet
Sheets("List569Combos").Select
Range("A1").Select
Application.ScreenUpdating = False
N = 1
Selection.ColumnWidth = 15
ActiveCell.Value = "Combinations"

' Change minimum value for A or maximum value for F
' to cover range of values to be covered
nMinA = 1
nMaxE = 69

' Start of loops for 5 variables (A-E)
For A = nMinA To nMaxE - 4
For B = A + 1 To nMaxE - 3
For C = B + 1 To nMaxE - 2
For D = C + 1 To nMaxE - 1
For E = D + 1 To nMaxE


' Verification of number of combinations posted
' and move to top of next column if 1048576
If N = 1048576 Then
Selection.ColumnWidth = 15
N = 1
ActiveCell.Offset(-1048576, 1).Select
Application.ScreenUpdating = True
Application.ScreenUpdating = False
ActiveCell.Value = "Combinations"
End If
 
Upvote 0

Forum statistics

Threads
1,214,877
Messages
6,122,051
Members
449,064
Latest member
scottdog129

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