+ Reply to Thread
Results 1 to 5 of 5

Returning random number from list formula

  1. #1
    Registered User
    Join Date
    05-09-2013
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2003, 2007 and 2013
    Posts
    12

    Returning random number from list formula

    Without the use of VBA, I have been trying to write a formula that returns a random value, from a column of values, ecluding 0's.

    Anybody know how to do this, without the use of VBA?

    Thank you

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Returning random number from list formula

    If A2:A10 is fully populated with numbers (some of which may be zero) then this array formula will give you one of the non-zero values, randomly. If there are repeated values then those values will be more likely to appear

    =INDEX(A2:A100,SMALL(IF(A2:A10<>0,ROW(A2:A10)-ROW(A2)+1),INT(RAND()*COUNTIF(A2:A10,"<>0")+1)))

    confirm with CTRL+SHIFT+ENTER
    Audere est facere

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Returning random number from list formula

    Maybe try something like this...

    R
    S
    T
    U
    27
    41.41
    8
    65.95
    28
    178.27
    1
    29
    52.61
    7
    30
    65.95
    6
    31
    75.33
    3
    32
    69.98
    5
    33
    136.53
    2
    34
    73.32
    4
    35
    13.2
    9
    36
    0
    10
    37
    0
    10
    38
    0
    10


    S27=RANK(R27,$R$27:$R$38)
    copied down
    U27=INDEX(R27:R38,MATCH(RANDBETWEEN(1,MAX(S27:S38)),S27:S38,0))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Returning random number from list formula

    Here is a formula that will generate random numbers without duplicates or zeros

    In A2 and copy down. In this example formula will generate numbers from 1 through 15. To increase the quantity of numbers change 15 to the desired number.

    =LARGE(ROW($1:$15)*NOT(COUNTIF($A$1:A1,ROW($1:$15))),RANDBETWEEN(1,(15+2-1)-ROWS(A$1:A1)))

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.


    A
    2
    8
    3
    10
    4
    9
    5
    12
    6
    6
    7
    2
    8
    3
    9
    5
    10
    15
    11
    14
    12
    4
    13
    1
    14
    13
    15
    11
    16
    7
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  5. #5
    Registered User
    Join Date
    05-09-2013
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2003, 2007 and 2013
    Posts
    12

    Re: Returning random number from list formula

    cheers guys. sorted now

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 09-02-2014, 03:49 PM
  2. Random List with input number from a selection list
    By alexaktung in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-26-2012, 06:24 AM
  3. generating random number list?
    By planetizzie in forum Excel General
    Replies: 10
    Last Post: 10-21-2009, 11:45 AM
  4. Replies: 9
    Last Post: 02-14-2009, 01:21 PM
  5. How do I find random number in list of random alpha? (Position is.
    By jlahealth-partners in forum Excel General
    Replies: 0
    Last Post: 02-08-2005, 02:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1