Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default select random value in a range of cells

I have a range of cells, eg (B10:B50) each cell containing
an integer.

How do I select a random integer that is in one of those cells?


I want a formula in cell so that that cell contains a random value
from that range.


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,572
Default select random value in a range of cells

=INDEX(B10:B50,INT(RAND()*50)+1)
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Pete Morris" <nospam.ple@se wrote in message
...
I have a range of cells, eg (B10:B50) each cell containing
an integer.

How do I select a random integer that is in one of those cells?


I want a formula in cell so that that cell contains a random value
from that range.



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,572
Default select random value in a range of cells

Sorry ... forgot how to count!

Use this:

=INDEX(B10:B50,INT(RAND()*41)+1)
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------

"Ragdyer" wrote in message
...
=INDEX(B10:B50,INT(RAND()*50)+1)
--
HTH,

RD

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

-
Please keep all correspondence within the NewsGroup, so all may benefit !
--------------------------------------------------------------------------

-
"Pete Morris" <nospam.ple@se wrote in message
...
I have a range of cells, eg (B10:B50) each cell containing
an integer.

How do I select a random integer that is in one of those cells?


I want a formula in cell so that that cell contains a random value
from that range.




  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default select random value in a range of cells


"Ragdyer" wrote in message
...
Sorry ... forgot how to count!

Use this:

=INDEX(B10:B50,INT(RAND()*41)+1)
--
HTH,

RD



Can you explain the logic behind that?

Why 41?

When I use it in a different range it doesn't work properly.


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,572
Default select random value in a range of cells

Here's a more simplified formula:

=INDEX(B10:B50,RAND()*42)

Now, the 42 is *1 more* then the size of the range (array), B10 to B50 which
contains 41 cells.

So, in a new range, if you had your specified numbers in A1 to A10, the
formula would be:

=INDEX(A1:A10,RAND()*11)

The Help files say that XL's Rand() function returns a random number which
is greater then or equal to 0, and *LESS* then 1, so *all* the possible
numbers are decimals!
I do believe that this is *not* true, since I cannot get Rand() to return
zero!
So, I would say that Rand returns numbers 0 and <1.

To convert these returns to larger numbers you just multiply the function.
However,
=Rand()*10
Will *NEVER* return 10, since 10 will *NEVER* be multiplied by 1.

Therefore, if your range contains 10 cells, and you want the possibility to
exist to return 10, simply multiply by the size of the range plus 1.

Now, the actual location of the range doesn't matter.
It could be A100 to A110.
When using Index(), the first cell of the *range* (A100) is always 1.
So this would work:
=Index(A100:A110,Rand()*12)
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Pete Morris" <nospam.ple@se wrote in message
...

"Ragdyer" wrote in message
...
Sorry ... forgot how to count!

Use this:

=INDEX(B10:B50,INT(RAND()*41)+1)
--
HTH,

RD



Can you explain the logic behind that?

Why 41?

When I use it in a different range it doesn't work properly.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to select top six numbers from a of range of random numbers Jack M Taylor Excel Worksheet Functions 4 January 30th 07 09:18 PM
Select a range but only sum the cells in a certain colour? jlm2184 Excel Worksheet Functions 1 March 24th 06 11:50 AM
Select Range of Cells programmingrookie Excel Discussion (Misc queries) 2 August 11th 05 07:13 PM
select a range using "cells()" fullers Excel Worksheet Functions 2 July 6th 05 06:00 PM
random selection from a range of cells tjb Excel Worksheet Functions 1 February 15th 05 06:34 PM


All times are GMT +1. The time now is 05:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"