PDA

View Full Version : Lottery



ndendrinos
11-19-2006, 09:35 AM
Bonjour,
There are 49 numbers and 7 are drawn (6 regular + 1 bonus)
DRJ posted a rather depressing worbook where he recons the odds of LOSING are about 99.95%
I on the other hand am an optimist and intend to WIN !
Here's how and need help:
I will list in A:A 1 to 49
I need a loop that will random pick 6 out of the 49 numbers CUT THEM and transpose them in range B1:G1
Next loop will do the same in range B2:G2 (but now there are empty cells in A:A ... maybe a problem ? ... if so can the code cut and shift up?)
At the end I will be left w/ 1 number in A:A

Not sure how much 6 regular lines and one of seven cost to play but I will play them and post the results.

The visual in DRJ's sample (found under "Lottery") is great ... the numbers can be seen changing at a rapid pace can you please help w/ this too?
Thank you

P.S anyone that helps with this will be remembered in my will

mdmackillop
11-19-2006, 11:45 AM
Sub LotteryList()
Randomize
For i = 1 To 49
Cells(i, 1) = i
Next
Range("B1:B49").Formula = "=RAND()"
Range("A1:B49").Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("B1:B49").ClearContents
For i = 1 To 48
Range("B1:G8")(i) = Range("A1:A48")(i)
Next
End Sub

ndendrinos
11-19-2006, 12:37 PM
Good afternoon mdmackillop,
Almost there ... the cutting is not taking place therefore I am not left with a single cell in AA .... the way the code works now (perfect BTW) I have to use a process of elimination to find the last number (the missing one)

As for the visual ...any way to add to the code to make it look like B9:B57 ... numbers changing at rapid paste ?

Here is a modified (ranges) book ... when all done I will edit the code to hide column B and start the end result in column C

Thanks a lot .

ndendrinos
11-19-2006, 12:50 PM
Ahem ... wrong attachment in previous answer here is the good one

mdmackillop
11-19-2006, 01:21 PM
The code is randomising the order of the column A cells, then writing them in order to the grid. The "spare" cell will always be the last, which I've copied to J1. I've added a loop to the code to run 10 times.

Sub LotteryList()
Randomize

For j = 1 To 10

For i = 1 To 49
Cells(i, 1) = i
Next
Range("B1:B49").Formula = "=RAND()"
Range("A1:B49").Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

For i = 1 To 48
Range("C1:H8")(i) = Range("A1:A48")(i)
Next
Range("J1") = Range("A49")
Next j
End Sub

ndendrinos
11-19-2006, 07:59 PM
Guess what I want visually can only happen if the random pick of numbers is done one number at a time .. then I can adjust "For J = 1 to 10" to get what I want.
Other than that ALL is great.
Since you're the only one in the running re : compensation for helping out with this posting here is the deal : I will post the numbers played BEFORE the draw and a short cut to the official Lotto 6/49 here in Canada.
Your share will be 25% ... paid immediately
I HOPE YOU WIN !!!