Welcome Guest
The time is now 7:33 pm
You last visited January 17, 2017, 6:20 pm
All times shown are
Eastern Time (GMT-5:00)

# Excel VBA - Generate Pairs & Trips to a Text File

Published:

Last Edited: August 10, 2010, 12:14 pm

1.  Create a new folder on your C: Drive and name it Lotto543 (c:\Lotto543)

2.  Open Excel and right-click any Tab at the bottom and select "ViewCode"

3.  When the Window opens go to the top Main Menu and select > Insert > Module

4.  Copy and paste the following code into the right workspace where you see the blinking cursor.

Sub Generate43C2()

Open "c:\Lotto543\L543.txt" For Output As #1

For i1 = 1 To 43 - 1
For i2 = i1 + 1 To 43 - 0

LexiNum = LexiNum + 1
Print #1, Format(LexiNum, "000") & " " & Format(i1, "0") & "," & Format(i2, "0")

Next
Next
Close #1

End Sub

=======================================================================

This generates all 903 Pairs for the 5/43 Lottery Game to a text file named L43.txt located at C:\Lotto543

If your drive designation is different from "C:\" then you will need to change the following code to reflect the code:

For example if your drive designation is the letter D:\ you would change th following line of code to the following:

Open "d:\Lotto543\L543.txt" For Output As #1

============================================================================

If your Lottery Game is a 5/39 game you can change or create a new folder and name the folder c:\Lotto539

and change the following code:

Sub Generate39C2()

Open "c:\Lotto539\L539.txt" For Output As #1

For i1 = 1 To 39 - 1
For i2 = i1 + 1 To 39 - 0

LexiNum = LexiNum + 1
Print #1, Format(LexiNum, "000") & " " & Format(i1, "0") & "," & Format(i2, "0")

Next
Next
Close #1

End Sub

=======================================================================

The "LexiNum" is actually the Lexicographic Pairs designation number.

The Excel formula for calculating the number of pairs in your lottery game is =COMBIN(43,2)  where "X" is the total number of balls (43) and "N" is the number of digits = 903 for a 5/43 game

or =COMBIN(39/2) = 741 Pairs for a 5/39 lottery game.

=======================================================================

For creating 3 Number Combinations (9,139) for a 5/39 Game =COMBIN(39,3).  This code below will generate all 9,139 trips to your folder C:\Lotto539.  If you open the folder you should see a text file L539Trips.txt inside the folder.  Remember to create your new folder c:\Lotto539 first before running the code.

Sub Generate39C3()

Open "c:\Lotto539\L539Trips.txt" For Output As #1

For i1 = 1 To 39 - 2

For i2 = i1 + 1 To 39 - 1

For i3 = i2 + 1 To 39 - 0

LexiNum = LexiNum + 1
Print #1, Format(LexiNum, "000") & " " & Format(i1, "0") & "," & Format(i2, "0") & "," & Format(i3, "0")

Next
Next
Next

Close #1

End Sub

======================================================================================

Good Luck!!

Entry #153

1.
Comment by GASMETERGUY - August 10, 2010, 9:03 pm
For those who do not program in Excel you must first call the VBA program. This is done by pressing "Alt" and F11 at the same time.
2.
Comment by luclc - September 28, 2010, 3:10 pm
this is outstanding,   the first time I got VBA (excel) to work with OPENOFFICE "calc",

can you please confirm.   I would like to use this with Pick3 or 6/49

for   6/49 I tried

code:

Sub Generate49C2()

Open "c:\Lotto649\L649.txt" For Output As #1

For i1 = 1 To 49 - 1
For i2 = i1 + 1 To 49 - 0

LexiNum = LexiNum + 1
Print #1, Format(LexiNum, "000") & " " & Format(i1, "0") & "," & Format(i2, "0")

Next
Next
Close #1

End Sub

You must be a Lottery Post member to post comments to a Blog.