+ Reply to Thread
Results 1 to 11 of 11

Rand Function Problem

  1. #1
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Rand Function Problem

    I have a column A1:M1 with numbers 1 - 13 and I wish to select 5 Random Numbers. I use O1:S1 for the Rand function. When I execute the function I sometimes end up with ### in one of the Rand Cells? Anyone know why this happens and how to make it stop? Thanks
    Last edited by ssjagger; 07-12-2011 at 02:42 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Rand Function Problem

    Assuming you don't want duplicates....have a look here: Random Numbers with No Duplicates
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Rand Function Problem

    I checked out the page you posted and I think there is something missing or maybe I'm reading it wrong??

    In Step 3 it says "In Lottery Range (A14:B19):" but there is nothing after it.

    Then it says "In column B, use the VLOOKUP and ROW functions in the following formula:
    =VLOOKUP((ROW()-ROW($A$19)+1),$B$2:$C$12,2,FALSE)"

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Rand Function Problem

    Ok, not sure about that, never actually followed it myself...

    But essentially, enter the RAND() function in 13 consecutive cells, say O1:AA1. Then in O2 or elsewhere enter: =RANK(O1,$O$1:$AA$1) copied across 5 columns.. to get 5 rand and unique numbers...

    If the 13 numbers in A1:M1 are not the numbers 1:13, then you can use INDEX() function to get relative positioned numbers...

  5. #5
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Rand Function Problem

    Ok, I see how that works.

    What I am using is =INDEX($A$1:$M$1,RAND()*COUNTA($A$1:$M$1)), but I still end up with #value (###) error in some of 5 cells that I input this formula? Sorry, I didn't realize it was a #value error until I made the column width larger. If I hit F9 a couple times, I will get 5 numbers, some of them are duplicates, but I'm wondering why I end up with this #value error?? Would removing duplicate's solve this? How would I write it? Thanks again

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Rand Function Problem

    Where is the RANK part... RAND() gives decimal values... so multiplying by COUNTA() will give a decimal value... and there are no decimal rows/columns....

    Can you post a sample workbook?

  7. #7
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Rand Function Problem

    Here's a sample.
    Attached Files Attached Files

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Rand Function Problem

    The attached is what I was talking about...
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Rand Function Problem

    I see how you've written this, but what if I want to use a non-consecutive set of numbers? I've attached a worksheet so you can see what I mean.
    Attached Files Attached Files

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Rand Function Problem

    My idea still works and ensures you don't get duplicates.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Rand Function Problem

    Sweet! I banged my head on the wall for days trying to figure out that one. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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