#### Picking Random Numbers

```I have been tasked with coming up with a form that will automatically assign
a random number to an individual with the click of a button.

The number is 7 digits in length.
Each element of the number can range from 1 to 9.

Something simular to a lottery number picker.

Does anyone have any sample code that I can refer to?

Dwight
```
 0
Utf
3/10/2008 6:56:07 PM
access 16762 articles. 3 followers.

3 Replies
647 Views

Similar Articles

[PageSpeed] 6

```Function GenerateRandomNumber() As String
Dim lngLoop As Long
Dim strResult As String

Randomize

For lngLoop = 1 To 7
strResult = strResult & Format((Int(9 * Rnd) + 1), "0")
Next lngLoop

GenerateRandomNumber = strResult

End Function

If what you want is the more usual digits ranging from 0 to 9, use

Function GenerateRandomNumber() As String
Dim lngLoop As Long
Dim strResult As String

Randomize

For lngLoop = 1 To 7
strResult = strResult & Format(Int(10 * Rnd), "0")
Next lngLoop

GenerateRandomNumber = strResult

End Function

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele

"Dwight" <Dwight@discussions.microsoft.com> wrote in message
news:87D6B078-D2CC-4761-AC44-12B70F43C241@microsoft.com...
>I have been tasked with coming up with a form that will automatically
>assign
> a random number to an individual with the click of a button.
>
> The number is 7 digits in length.
> Each element of the number can range from 1 to 9.
>
> Something simular to a lottery number picker.
>
> Does anyone have any sample code that I can refer to?
>
> Thanks in advance!
>
> Dwight

```
 0
Douglas
3/10/2008 7:12:32 PM
```Try this --
Round(Rnd() * 9999999, 0) + 1

If your table has an Autonumber as primary key then try this --
Right(Left((.46345679/[aaa])*100000,15),7)
--
KARL DEWEY
Build a little - Test a little

"Dwight" wrote:

> I have been tasked with coming up with a form that will automatically assign
> a random number to an individual with the click of a button.
>
> The number is 7 digits in length.
> Each element of the number can range from 1 to 9.
>
> Something simular to a lottery number picker.
>
> Does anyone have any sample code that I can refer to?
>
> Thanks in advance!
>
> Dwight
```
 0
Utf
3/10/2008 7:24:24 PM
```Thank you!

"Douglas J. Steele" wrote:

> Function GenerateRandomNumber() As String
> Dim lngLoop As Long
> Dim strResult As String
>
>   Randomize
>
>   For lngLoop = 1 To 7
>     strResult = strResult & Format((Int(9 * Rnd) + 1), "0")
>   Next lngLoop
>
>   GenerateRandomNumber = strResult
>
> End Function
>
> If what you want is the more usual digits ranging from 0 to 9, use
>
> Function GenerateRandomNumber() As String
> Dim lngLoop As Long
> Dim strResult As String
>
>   Randomize
>
>   For lngLoop = 1 To 7
>     strResult = strResult & Format(Int(10 * Rnd), "0")
>   Next lngLoop
>
>   GenerateRandomNumber = strResult
>
> End Function
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Dwight" <Dwight@discussions.microsoft.com> wrote in message
> news:87D6B078-D2CC-4761-AC44-12B70F43C241@microsoft.com...
> >I have been tasked with coming up with a form that will automatically
> >assign
> > a random number to an individual with the click of a button.
> >
> > The number is 7 digits in length.
> > Each element of the number can range from 1 to 9.
> >
> > Something simular to a lottery number picker.
> >
> > Does anyone have any sample code that I can refer to?
> >
> > Thanks in advance!
> >
> > Dwight
>
>
>
```
 0
Utf
3/10/2008 7:34:00 PM

Similar Artilces:

How do I randomize words within a row?
I need to set up a random order list for 3 studies I'm running. We'll call them A, B and C. I need each of my subjects to run A,B,C but in a random order. Is there a way to randomize within rows in Excel...that seems to be the only way I can think of to creat this list(i have about 100 subjects). Any suggestions would be greatly appreciated. One was to do it would create a column (call it sort) in that column I would use the Function =RAND() This will generate a random number between 0 and 1. Then you sort the file by the Sort Column and that should randomize it. Note that ever...

Grouping patters of numbers in cell
Sir , i want to numbers written in cells be displayed as grouped in indian format i.e. a number of 123456.00 can how be automatically group as 1,23,456.00 instead of 123,456.00 Format as Custom, #\,##\,###.00 "eereokatohar" wrote: > Sir , > i want to numbers written in cells be displayed as grouped in indian format > i.e. a number of 123456.00 can how be automatically group as 1,23,456.00 > instead of 123,456.00 [>=10000000]##\,##\,##\,##0.00;[>=100000]##\,##\,##0.00;##,##0.00 will format say 1234567890 as 123,45,67,890.00 -- HTH Bob Phillips (replace...

How can I count the number of entries in a column?
I wish to construct Auction Lists for my Philatelic Society. At present I make the list up in an Acces DB and then transfer it to Excel (2003). At this point I add extra columns to cater for "Bidders #'s"; "Selling price"; "Price to Buyer";"Return to Vendor"; & "Return to Club", complete with relevant formulae. So far so good, I now wish to add, at the base of these columns, via a macro initially, a summary of data as entered. I also want to show, and use, in order to locate this data, the "TOTAL NUMBER OF LOTS". Si...

count number of cells
Hi all, I have searched for a way to get the answer of how many of cells in column returning a value from other cells. I have tried =count(A1:A10;A12:A19;A21:A30) which works fine althoug the cells containing formulas, but, when having this formula: =IF(G44<=20;0;IF(AND(G44=C44;F44<=20;G44>20);(G44-20);IF(AND(G44>C44;C44>20);C44-20;IF(AND(G44<C44;G44>20);G44-20; ")))), I dont get the expected result. I suppose that somewhere in that formula there is a statement that mess it up. Whats wrong, and what to do about it to get the right result Any ideas anyone? //Th...

chart with outsized number
i have a chart in which one number is 17000 while the range for the other data points range from 9 to 4000 with most of the data points below 1500. the data point with 17000 distorts the rest of the data, i.e. you can't see subtle shifts at the lower ranges. is there a way to correct this problem? thanks in advance for your help -- aprilshowers What type of charts are they? 2 column charts? Column and a line chart? Which version of EXCEL are you using? "april" wrote: > i have a chart in which one number is 17000 while the range for the other &g...

#VALUE!
Hi All, I have created a monster spreadsheet that pulls in data from other spreadsheets (12 in all). Now I have it pull the information from each spreadsheet into its own rows. I then have a total so (=a1+a2+a3+a4 etc) but it is returning the error #VALUE! Now I believe this is because the data I'm adding is formatted as text even though its a number. How can I format this back to be truly a number? -- Thanks Adam ==================== Windows XP Pro + Office 2003 Pro Try copying an empty cell and then select your range and Edit|paste special|check Add under Operation. Did ...

Convert numbers from text format to number format
I have retrieved some data from external source and it put to my worksheet in one column numbers in text format and if I want to work with numbers (add, substract, etc.) I need it to convert to number format. I tried to select column and mark it as number format however it doesn´t work. Pls help me what to do, how to suceed. I have no chance to change the format in source. Juraj Hi Merlin68, > I have retrieved some data from external source and it put to my > worksheet in one column numbers in text format and if I want to work > with numbers (add, substract, etc.) I need i...

Number formatting error
We're working with a workbook with 115 rows of data. Most are numbers, some are text and some are blank. The last rows contain formulas using count and avg. These formulas return the wrong results since, even though the cells are formatted as numbers, Excel doesn't see them as numbers. The help file contains a procedure to multiply the cells by 1. This seems to change things so that Excel recognizes them as numbers and things compute correctly. The concern is that it would be easy to miss the problem and thus work with incorrect data. Is there a solution so that Excel always recognize...

Project number available on purchase order?
I noticed there is a field called ProjNum in the POP10110 Purchase Order Line table; how does it get populated? We'd like to be able to put something in it, but I can't find a screen with it available. -- Bud Cool, Accounting System Manager HDA, Inc. Hazelwood, MO GP 9.0, SP2 There is also a "Cost Category" field in addition to Project Number but you'll need to implement MS Project Accounting module to use the fields. Or build your own application to use the fields. "Bud" wrote: > I noticed there is a field called ProjNum in the POP10110 Purchase Or...

I wanna show days and numbers automatically or with formulas
Hi, I want to build a kind of schedule, so that if I write or introduce the month in a cell the first row shows all the days of the month and in the second all the days of the week corresponding to each number of day. Is this possible? Thank you. >if I write or introduce the month in a cell And how will you be doing that? A1: Jan A1: January A1: 1/1/2009 -- Biff Microsoft Excel MVP "bren" <srtaele@gmail.com> wrote in message news:328225f0-995e-4586-b582-7df9de98dd0c@z41g2000yqz.googlegroups.com... > Hi, > > I want to build a kind...

row number of last non-blank cell
I've tried a bunch of ideas but no luck yet. I used to use COUNTA() to find the number of cells in a column so I could create an array reference to the range of cells with values using OFFSET(). Now my column may have some blank entries. COUNTA() still returns the number of non-blank cells so my range array falls short by the number of blank cells. How can I find the row number of the last cell that is not blank. I need this in a worksheet function, not a macro or not selecting with menu commands. Thanks... What type of data is in the range? Is it text, numeric, ...

increasing the number of rows of a worksheet beyond 65536?
is it possible to increase the number of rows of a worksheet beyond 65536? if yes, how? if no, any workarounds? I need to read in a text file in CSV format with more than 1,000,000 lines. thanks! Hi Split your file to several files with <65536 rows in each. You can use any text editor, capable open your file, for this. Create a copy of original file, and delete all rows except # first ones (# being the number of rows you want to left in file). Then create a next copy of original file, and delete # rows at top, and then all rows except # first ones, and so on. -- Arvi Laanemets (When...

Fina number of records between 2 percentile values
How do i find the number of test scores between the 50th and 75th percentile? Formula using now is =countif(data cells in range, "<=" &value of 75th percentile) -countif(data cells in range, ">" &value of 50th percentile) -number of records -1 Thanks in advance! =SUMPRODUCT((B1:B10>=50%)*(B1:B10<=75%)) "coo-too" wrote: > How do i find the number of test scores between the 50th and 75th percentile? > Formula using now is > =countif(data cells in range, "<=" &value of 75th percentile) -countif(data > cells i...

Least number of digits in Y-axis labels
I'm looking for an automatic way to format the value axis with the least number of digits possible after the decimal. I want the format to switch from #,##0 to #,##0.0 to #,##0.00, etc. as needed. That is, I never want the Y axis to display the same number twice, because that means we need to add more digits to the right of the decimal. And I never want the Y axis to display "0" in every right-most character after the decimal, because that means we need to reduce the number of digits displayed. Other than using macros, can anyone suggest a way to display the least number...

Moving. Want to number boxes and inventory contents of boxes
Using Excel in MS Office 2003. I'm moving household. Will have approx 200 boxes Want to record the number of each box, contents of each box and the room it will go into in the new house. For instance I'd like to be able to do a search and locate the box which has a black wood skirt is in. i.e. Bedroom #1 Box 8: 10 Skirts 5 Blouces 15 Slacks I'm a novice at Excel and would appreciate any help you can give. Hi Cari i think excel wouldn't be the best program to use for your wishes. I would recommend MSAccess to you. There you could setup diffrent tables for rooms, bo...

How to sort random numbers in columns
I need to insert numbers out of order in columns, how can I sort them into correct order in columns. Select your range and do Data|sort??? (Not sure if I understood the real question, though.) webehere wrote: > > I need to insert numbers out of order in columns, how can I sort them into > correct order in columns. -- Dave Peterson That doesn't work. I have approx 5000 items to scan into a file, they are numbered 1 thru 5000. i have to scan them out of order. I want to keep a list of scanned items in numerical order. but, I have to scan them at random. I need to enter t...

Outlook Number Points
Hi When you create a new Email> or reply> the numbering points 1,2,3 etc are set to use Times New Roman - is there any way to change it to use a different font as its default I have set the Normal.dot to have the default of Arial 10 but this has only changed text and not the numbering points. ...

How can I get the version number of the installed Speech API?
Till now my MFC program uses TextToSpeech by means of the Speech SDK and SAPI 5.0. For a certain reason I must now use SAPI 5.1. Therefore I must make in my program the following decision: nothing yet installed => install SAPI 5.1 SAPI 5.0 installed => install SAPI 5.1 SAPI 5.1 installed => do nothing Can I somehow get in my MFC program the current SAPI version number with e.g. a SAPI function or similar? Thanks for any helpful comments. Eddy "Eddy" <Eddy@discussions.microsoft.com> wrote in message news:D51C8B3D-4996-43F8-8238-D8F15DC52...

How do I leave the first page of a series unnumbered? Silver ...

Let Excel choose next following document number
I want to make a document which has the following purpose: claiming the next number of a purchase order, quotation or another document. >From a lookup table and a combo box/drop down the person chooses wether its a PO or Q. Then in the neighboring cell appears the next number of that document. So, numbers already claimed before cannot be choosed. How to perform that? (But, with the possibility to clear the field and to have the claim be undone) So it's like this: choose document PO / Q | next claimed # appears | Person who claims (manual choose) Optionally, but I hope it'...

Converting formula to number
I have a excel 2003 worksheet and I would like to convert the formula to number within this worksheet is this possible, how can I do that Thank You If you want the result of the formula in the cell, just copy the cell and (edit) PASTE SPECIAL. You can select to paste the value of the cell in the cell. "msw" <msw@hotmail.com> wrote in message news:uAO8R%23HBFHA.2112@TK2MSFTNGP09.phx.gbl... > I have a excel 2003 worksheet and I would like to convert the formula to > number within this worksheet is this possible, how can I do that > > Thank You > > I w...

In Publisher how do I get invoice numbers to update automatically
I am setting up my invoices using Publisher. I have got the date to change automatically, but can I also get the invoice number to change automatically? Thank you. Joe Use Mail Merge. -- JoAnn Paules MVP Microsoft [Publisher] Tech Editor for "Microsoft Publisher 2007 For Dummies" "Mojostone" <Mojostone@discussions.microsoft.com> wrote in message news:7553BE65-97D5-4AAA-AE66-91950B71AB1F@microsoft.com... >I am setting up my invoices using Publisher. I have got the date to change > automatically, but can I also get the invoice number to change > autom...

Need to convert the numbers with tolerances
I have a column of numbers in teh format 0.45+_0.23 . +_ is a character plus or minus . How can I convert the number before and after +_ into mm automatically ? Any formula ? - Vijay v_udupa@hotmail.com On Jan 8, 10:40=A0pm, Jambar <vijayad...@gmail.com> wrote: > I have a column of numbers in teh format 0.45+_0.23 =A0 . +_ is a > character plus or minus . > How can I convert the number before and after +_ into mm > automatically =A0? Any formula ? I presume the "numbers with tolerances" are actually in Text format. Depends on the exact format of the number st...

How do I restart page numbering in Publisher 2000?
I'm using Publisher 2000 and need to begin page numbering on the third page of the document, but it should print with "1" on that page (not 3) and continue from there. Internet help for later versions of Publisher says to right click on that page in the Page Navigation tool and insert a section. Please tell me there's a way to restart page numbering within a document in Publisher 2000! Thanks. TaRHicks wrote: > I'm using Publisher 2000 and need to begin page numbering > on the third page of the document, but it should print > with "1" on that pa...

How to limit the number of accepted meeting requests in Outlook 20
Is there a way to limited the number of accepted meeting requests in Outlook 2007 Calendar "triumph615" <triumph615@discussions.microsoft.com> wrote in message news:B74DD0B6-C113-416E-99A2-8762D8FB23D0@microsoft.com... > Is there a way to limited the number of accepted meeting requests in Outlook > 2007 Calendar No need to post multiple times. -- Brian Tillman [MVP-Outlook] ...