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
[TABLE="width: 487"]
<colgroup><col><col span="6"></colgroup><tbody>[TR]
[TD]DRAWN[/TD]
[TD]19[/TD]
[TD]38[/TD]
[TD]13[/TD]
[TD]41[/TD]
[TD]43[/TD]
[TD]03[/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"]18[/TD]
[TD="align: right"]14[/TD]
[TD="align: right"]31[/TD]
[TD="align: right"]24[/TD]
[TD="align: right"]39[/TD]
[TD="align: right"]2[/TD]
[/TR]
</tbody>[/TABLE]
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
[TABLE="width: 487"]
<colgroup><col><col span="6"></colgroup><tbody>[TR]
[TD]DRAWN[/TD]
[TD]19[/TD]
[TD]38[/TD]
[TD]13[/TD]
[TD]41[/TD]
[TD]43[/TD]
[TD]03[/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"]18[/TD]
[TD="align: right"]14[/TD]
[TD="align: right"]31[/TD]
[TD="align: right"]24[/TD]
[TD="align: right"]39[/TD]
[TD="align: right"]2[/TD]
[/TR]
</tbody>[/TABLE]