Consulting

Results 1 to 6 of 6

Thread: Lottery

  1. #1
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location

    Lottery

    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
    Thank you for your help

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]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
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    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 .


    Thank you for your help

  4. #4
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    Ahem ... wrong attachment in previous answer here is the good one
    Thank you for your help

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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.
    [vba]
    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

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    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 !!!
    Thank you for your help

Posting Permissions

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