ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Random Selection (https://www.excelbanter.com/excel-programming/334161-random-selection.html)

petevang[_3_]

Random Selection
 

Can excel be used to randomly select numbers within a group. Ex I need
to randomly select 14 accounts aout of a list of 150. How can I do
this?


--
petevang
------------------------------------------------------------------------
petevang's Profile: http://www.excelforum.com/member.php...o&userid=25034
View this thread: http://www.excelforum.com/showthread...hreadid=386134


Rich_z[_26_]

Random Selection
 

You don't say if the accounts are consecutively numbered or not.

If they are consecutively numbered you can use:


Code:
--------------------

int(1+(150*rnd(1)))

--------------------


If they are not consecutively numbered then place the accounts into an
array numbered 1-150 and use the formula above to generate a pointer
into the array (likewise if the accounts are non-numeric)

RND is a psuedo Random number generator. This means that it's results
are reproduceable (if you restart Excel...).

To reproduce a given set of 'Random' numbers you use the 'Randomize'
statement.

To give the numbers an almost totally random nature, use the
statement:


Code:
--------------------

Randomise(Now())

--------------------



Code:
--------------------

Sub Temp1()
Dim I As Integer
'*
Randomize (Now())
For I = 1 To 14
Debug.Print Int(1 + (150 * Rnd(1)))
Next I
End Sub

--------------------


Gives the following results over 3 runs:

94
78
114
67
85
52
79
95
124
58
36
40
125
132

46
47
35
46
81
100
33
70
143
150
120
37
51
140

122
21
14
93
45
24
122
52
101
92
148
71
98
133


If you want to make sure a number is not used twice then you will have
to build an array of the numbers chosen (either in a string or using
Redim)

Regards

Rich


--
Rich_z
------------------------------------------------------------------------
Rich_z's Profile: http://www.excelforum.com/member.php...o&userid=24737
View this thread: http://www.excelforum.com/showthread...hreadid=386134


Tom Ogilvy

Random Selection
 
put the list of 150 accounts in column A starting in row1

in column B put in

=rand()

and drag down.

Then sort A1:B150 on column B.

Take the first 15 accounts

--
Regards,
Tom Ogilvy

"petevang" wrote in
message ...

Can excel be used to randomly select numbers within a group. Ex I need
to randomly select 14 accounts aout of a list of 150. How can I do
this?


--
petevang
------------------------------------------------------------------------
petevang's Profile:

http://www.excelforum.com/member.php...o&userid=25034
View this thread: http://www.excelforum.com/showthread...hreadid=386134





All times are GMT +1. The time now is 10:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com