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
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