VideoPhoto

23 May, 2021

Pick your lucky Lotto numbers

If you play Lotto, how do you pick your lucky numbers?

Everyone has their own method. Some people like to analyze past draws and study the statistics to select potential winning patterns. Others rely on totally random ways. My own experience shows that statistics helps a little bit with winnings at the low end only. That’s it.

No method can guarantee a big win. Lotteries are completely random. To check out my 'independent' serendipity - years ago - I decided to create my own Lotto number picker coded with VBA. It’s one of my modest and oldest Excel creations. Here's its face in a worksheet:

Simple and functional. It just picks six lucky numbers for you to play in a lottery like Lotto649 or something close to it. It can be modified quite easily for other lottery games based on random selections. You can get your very own quick picks on your own computer.

Copy the VBA code listed below and paste it to a Module in your VBA project (go there by using ALT+F11 shortcut). Switch back to your worksheet and click on Developer tab to Insert (in the Controls group) the rectangular Button from Form Controls. Click he worksheet location where you want the button to appear and expand it there. The assign Macro window appears. Assign the Draw649 macro to the button and click OK. Right-click on it and then click Format Control to specify properties of the button.

Give it a try. Adjust the location of your control button, if necessary. Get your first lucky numbers.

Good luck!

I'd like to be the first to congratulate you if you pick the right numbers at the right time. So please remember the source of inspiration...😉

Here's the code:

Sub Draw649()
'Selects randomly 6 numbers from 1 to 49
Application.ScreenUpdating = False
    Range("B2:H8").Select
    Selection.RowHeight = 25
    Selection.ColumnWidth = 4
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    With Selection.Interior
        .ColorIndex = 36
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
    End With
    Range("A2").Select
    Selection.ColumnWidth = 1
    Range("I2").Select
    Selection.ColumnWidth = 1
    Range("A1:I9").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlDouble
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlDouble
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlDouble
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlDouble
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    With Selection.Interior
        .ColorIndex = 40
        .Pattern = xlGray50
        .PatternColorIndex = 2
    End With
    Range("B2:H8").Select
    With Selection.Font
        .Name = "Georgia"
        .Size = 14
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
    With Selection.Interior
        .ColorIndex = 19
        .Pattern = xlGray50
        .PatternColorIndex = 2
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlHairline
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlHairline
        .ColorIndex = xlAutomatic
    End With
    Range("B2").Select
CountN = 0
CountC = 0
CountR = 0
Numbr = 0
Randomize
Do While (CountN < 6)
    CountC = Int(Rnd() * 7 + 2)
    CountR = Int(Rnd() * 7 + 2)
    Cells(CountR, CountC).Select
    If Cells(CountR, CountC).Value = "" Then
        Numbr = (CountR - 2) * 7 + CountC - 1
        Select Case Numbr
            Case 1 To 49
                Cells(CountR, CountC).Value = Numbr
                With Selection.Borders(xlEdgeLeft)
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                With Selection.Borders(xlEdgeTop)
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                With Selection.Borders(xlEdgeBottom)
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                With Selection.Borders(xlEdgeRight)
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                With Selection.Interior
                .ColorIndex = 34
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                End With
                CountN = CountN + 1
            Case Else
                Numbr = 0
            End Select
    End If
Loop
Application.ScreenUpdating = True
Range("AA1").Select
a = MsgBox("Clear the window?", vbOKOnly)
Range("A1:I9").Select
Range("A1:I9").Clear
Selection.RowHeight = 12.75
Selection.ColumnWidth = 8
Range("A1").Select
End Sub

No comments:

Post a Comment

All comments are held for moderation. I reserve the right to edit, censor, delete and - if necessary - block comments.