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




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

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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