Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
kathyxyz
 
Posts: n/a
Default How to randomly select from a list with condition


I have a list of twenty real number in A1 to A20.
How can I randomly select a number from the list, but not the one with
value = 0
If the selected number is zero, it will automatically select another
random number from the list.
The list is dynamic, so I don't know exactly when and where the ones
with zero value show up.
Thank you.

Katherine.


--
kathyxyz
------------------------------------------------------------------------
kathyxyz's Profile: http://www.excelforum.com/member.php...o&userid=25624
View this thread: http://www.excelforum.com/showthread...hreadid=390385

  #2   Report Post  
Morrigan
 
Posts: n/a
Default


With 2 helper columns, you can try something like this:

A3:A20 = your data

B3 = IF(A3=0,500,ROW()) (Copy down)
C3 = SMALL(B$3:B$20,ROW()-2) (Copy down)

D3 =
OFFSET(A3,INDIRECT("C"&RANDBETWEEN(ROW(),ROW()+COU NTIF(C3:C20,"<500")-1))-ROW(),0)


Hope this helps.



kathyxyz Wrote:
I have a list of twenty real number in A1 to A20.
How can I randomly select a number from the list, but not the one with
value = 0
If the selected number is zero, it will automatically select another
random number from the list.
The list is dynamic, so I don't know exactly when and where the ones
with zero value show up.
Thank you.

Katherine.



--
Morrigan
------------------------------------------------------------------------
Morrigan's Profile: http://www.excelforum.com/member.php...fo&userid=7094
View this thread: http://www.excelforum.com/showthread...hreadid=390385

  #3   Report Post  
kathyxyz
 
Posts: n/a
Default


Thanks, Morrigan!

Katherine


--
kathyxyz
------------------------------------------------------------------------
kathyxyz's Profile: http://www.excelforum.com/member.php...o&userid=25624
View this thread: http://www.excelforum.com/showthread...hreadid=390385

  #4   Report Post  
olasa
 
Posts: n/a
Default


It can also be calculated in a single cell:

=INDEX(LARGE(A1:A20,ROW(INDIRECT("1:"&(COUNT(A1:A2 0)-COUNTIF(A1:A20,0))))),RANDBETWEEN(1,COUNT(A1:A20)-COUNTIF(A1:A20,0)))


Ola Sandström


--
olasa
------------------------------------------------------------------------
olasa's Profile: http://www.excelforum.com/member.php...o&userid=17760
View this thread: http://www.excelforum.com/showthread...hreadid=390385

  #5   Report Post  
Morrigan
 
Posts: n/a
Default


Just a quick note if you are using Olasa's formula, all data must be
positive numbers.


olasa Wrote:
It can also be calculated in a single cell:

=INDEX(LARGE(A1:A20,ROW(INDIRECT("1:"&(COUNT(A1:A2 0)-COUNTIF(A1:A20,0))))),RANDBETWEEN(1,COUNT(A1:A20)-COUNTIF(A1:A20,0)))


Ola Sandström



--
Morrigan
------------------------------------------------------------------------
Morrigan's Profile: http://www.excelforum.com/member.php...fo&userid=7094
View this thread: http://www.excelforum.com/showthread...hreadid=390385



  #6   Report Post  
olasa
 
Posts: n/a
Default


Thanks for spotting that Morrigan.
This works with both positive and negative number

=INDEX(LARGE(IF(A1:A20=0,"",A1:A20),ROW(INDIRECT(" 1:"&(COUNT(A1:A20)-COUNTIF(A1:A20,0))))),RANDBETWEEN(1,COUNT(A1:A20)-COUNTIF(A1:A20,0)))

However this formula MUST be confirmed by holding down Ctrl and Shift,
and then hit Enter.

Ola Sandström


--
olasa
------------------------------------------------------------------------
olasa's Profile: http://www.excelforum.com/member.php...o&userid=17760
View this thread: http://www.excelforum.com/showthread...hreadid=390385

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 do I Select Multiple entries from Valid list for a Cell WIDBIS Excel Discussion (Misc queries) 1 June 29th 05 12:53 AM
Making pick list conditional on selection from previous pick list Stewart Excel Discussion (Misc queries) 1 June 27th 05 11:30 AM
subtotaling and manipulating a list of data TJN Excel Worksheet Functions 0 April 27th 05 10:31 PM
List box not being displayed in second worksheet Brian Excel Discussion (Misc queries) 2 January 27th 05 04:35 PM
select unique to make list Spunky Excel Worksheet Functions 2 November 23rd 04 08:19 PM


All times are GMT +1. The time now is 02:28 AM.

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"