HearMePlease
New Member
- Joined
- Jul 26, 2018
- Messages
- 6
Good morning Masters,
Please help me to update the codes below. My situation is I want to stop the codes running if it all the numbers in the Drawn Row are already present in the Ticket No 1 Row even if it is not on the same order as in the drawn. A message box will appear once this is achieved and how many times it is run.
Sub lotto_no()
'Define your variabiles
lowerbound = 1
upperbound = 45
Set randomrange = Range("B2:b7")
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
Static cnt As Long
cnt = cnt + 1
MsgBox "I have been clicked " & cnt & " times"
End Sub
<colgroup><col><col span="6"></colgroup><tbody>
</tbody>
Please help me to update the codes below. My situation is I want to stop the codes running if it all the numbers in the Drawn Row are already present in the Ticket No 1 Row even if it is not on the same order as in the drawn. A message box will appear once this is achieved and how many times it is run.
Sub lotto_no()
'Define your variabiles
lowerbound = 1
upperbound = 45
Set randomrange = Range("B2:b7")
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
Static cnt As Long
cnt = cnt + 1
MsgBox "I have been clicked " & cnt & " times"
End Sub
DRAWN | 19 | 38 | 13 | 41 | 43 | 03 |
Ticket | No 1 | No 2 | No 3 | No 4 | No 5 | No 6 |
Ticket No 1 | 18 | 14 | 31 | 24 | 39 | 2 |
<colgroup><col><col span="6"></colgroup><tbody>
</tbody>