Lottery in VBA

zip.survey

Board Regular
Joined
Sep 8, 2006
Messages
55
I've searched all over for a simple code and can't find it. All I want to do is randomly display six different numbers that can be anywhere from 1-52 but cannot be duplicated in those six boxes.
 
thanks shippey this is nice.. i will mess with this some.... do you or is anyone else out there willing to help with the loop i am wanting to do?
id like the sheet to refresh the randomly generated numbers until G5 -G10 =6 and count how many times it had to refresh this could be displayed in column H5:H10.. any help with this part of it would be appreciated
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
sorry my friend not really experienced enough in excel VBA to do what you require, but as i understand it you are wanting to

type 6 numbers, then run a random number generator producing 6 new numbers which are to be checked against your typed 6, and keep repeating until all 6 matched, ill check back in tommorow to see how you are getting on, ill have a look see what i can find if im not too busy at work tommorow
 
Upvote 0
that is exactly right. on this thread we have alrady built the random number generator. and we are currently able to tell how many matches we have on each set of 6 numbers. now looking to see how many times those numbers need to refresh before we get all 6 to match. that would be interesting to see.. :) i am expecting quite a high number... thanks shippey for all your help. replys and help is always appreciated at least by me... :biggrin:
 
Upvote 0
Book1
ABCDEFGHIJKLMN
1512529181716
2
3
4
5
64714134326370FALSEFALSEFALSEFALSEFALSEFALSE
7
8
Sheet1


i set out the sheet as above the formulas used are

cells A1:F1
Code:
=RANDBETWEEN(1,52)

cells a6:f6 are just numbers entered

cell G6 is
Code:
=COUNTIF(H6:M6,"true")

and finally H6:m6
Code:
=OR(A6=$A$1:$F$1)
paste the first code into H6 and press CTRL + SHIFT + ENTER to accept the formula else you will get #VALUE error

the VBA code i used is very simple as is

Code:
Sub Macro1()

x = 0 ' this sets the value of X to zero
   Do Until y = 6 ' this says do until Y = 6
   y = [g6].Value ' this reads the value of Y from cell G6
   Calculate ' this refreshes the sheet
   x = x + 1 ' this adds 1 to the value of X
   Loop
    MsgBox x ' when the value of Y reaches 6 a message box will appear with the number of X
            ' which was the number of refreshes that was made i ran the code for 20 minutes
           ' and didnt get 6 to match
    End Sub
 
Upvote 0
just an update, i ran my code overnight and it was still running this morning when i returned to work, approx 17 hours, i stopped it using CTRL + BREAK just incase you didnt know how to stop it, i noticed that my number were not unique, so i used HOTPEPPER's method to generate the numbers and will run it again to see what i get

HTH
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,211
Members
448,554
Latest member
Gleisner2

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