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.

DRAWN342028173116
TicketNo 1No 2No 3No 4No 5No 6
Ticket No 1343340373013
Ticket No 22127464312
Ticket No 32693910143
Ticket No 4152817161819
Ticket No 542322253544
Ticket No 63825284541

<tbody>
</tbody>



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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,215,491
Messages
6,125,102
Members
449,205
Latest member
ralemanygarcia

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