Row2 6 numbers are present in row4 6 random numbers

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




DRAWN193813414303
TicketNo 1No 2No 3No 4No 5No 6
Ticket No 118143124392

<colgroup><col><col span="6"></colgroup><tbody>
</tbody>
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,215,503
Messages
6,125,175
Members
449,212
Latest member
kenmaldonado

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