Lotto number results counter

HearMePlease

New Member
Joined
Jul 26, 2018
Messages
6
Good afternoon Masters,

I have some codes that comes from other users regarding lotto numbers generators. I want to update it by getting the combination of the previous lotto results which I have entered above the file, then a message box will show how many time we run the vba codes before we achieve those numbers.

[TABLE="width: 487"]
<tbody>[TR]
[TD]DRAWN[/TD]
[TD]34[/TD]
[TD]20[/TD]
[TD]28[/TD]
[TD]17[/TD]
[TD]31[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Ticket[/TD]
[TD]No 1[/TD]
[TD]No 2[/TD]
[TD]No 3[/TD]
[TD]No 4[/TD]
[TD]No 5[/TD]
[TD]No 6[/TD]
[/TR]
[TR]
[TD]Ticket No 1[/TD]
[TD="align: right"]34[/TD]
[TD="align: right"]33[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]37[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]13[/TD]
[/TR]
[TR]
[TD]Ticket No 2[/TD]
[TD="align: right"]21[/TD]
[TD="align: right"]27[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]12[/TD]
[/TR]
[TR]
[TD]Ticket No 3[/TD]
[TD="align: right"]26[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]39[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]14[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]Ticket No 4[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]28[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"]16[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]19[/TD]
[/TR]
[TR]
[TD]Ticket No 5[/TD]
[TD="align: right"]42[/TD]
[TD="align: right"]32[/TD]
[TD="align: right"]22[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]35[/TD]
[TD="align: right"]44[/TD]
[/TR]
[TR]
[TD]Ticket No 6[/TD]
[TD="align: right"]38[/TD]
[TD="align: right"]25[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]45[/TD]
[TD="align: right"]41[/TD]
[/TR]
</tbody>[/TABLE]



Sub lotto_no()
'Define your variabiles
lowerbound = 1
upperbound = 45
Set randomrange = Range("B2:G7")

randomrange.Clear
For Each rng1 In randomrange
counter = counter + 1
Next

If counter > upperbound - lowerbound + 1 Then
MsgBox ("Number of cells > number of unique random numbers")
Exit Sub
End If

For Each Rng In randomrange
randnum = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Do While Application.WorksheetFunction.CountIf(randomrange, randnum) >= 1
randnum = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Loop
Rng.Value = randnum
Next
End Sub

Thanks and Regards,


HearMePlease
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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