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.
<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
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.
DRAWN | 34 | 20 | 28 | 17 | 31 | 16 |
Ticket | No 1 | No 2 | No 3 | No 4 | No 5 | No 6 |
Ticket No 1 | 34 | 33 | 40 | 37 | 30 | 13 |
Ticket No 2 | 21 | 27 | 4 | 6 | 43 | 12 |
Ticket No 3 | 26 | 9 | 39 | 10 | 14 | 3 |
Ticket No 4 | 15 | 28 | 17 | 16 | 18 | 19 |
Ticket No 5 | 42 | 32 | 22 | 5 | 35 | 44 |
Ticket No 6 | 38 | 25 | 2 | 8 | 45 | 41 |
<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