+ Reply to Thread
Results 1 to 5 of 5

Random Selections

  1. #1
    Registered User
    Join Date
    03-02-2009
    Location
    St Ives
    MS-Off Ver
    Excel 2003
    Posts
    2

    Random Selections

    Hi
    Wondering if anyone can assist. I have workbook with 10 worksheets. Each worksheet consists of a class. I would like to create a random selection of say 27 pupils selected randomly from each class(worksheet). Is there a way that I could use the random function to achieve this or is there any way that this can be achieved. Use Office 2003 with SP2.
    Thanks in Advance

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Random Selections

    Do you want to do this with formulas or a macro? Is the number of students variable from class to class? Do you know how many students there are in each class?

    What I am thinking is you can use two calls to the random number function. The first one would select the class (1-10) and then the second would select the student in the class (1-n). For example, say that you want to randomly select a class and that the worksheets are named "Classn", then the function in cell A1:
    =CONCATENATE("Class", TRUNC(RAND()*10,0)+1)
    would select a class sheet. Then, say the number of students in each class is in cell A1 of the class sheet, then a random student number placed in B1 from classn would be
    =TRUNC(RAND()*INDIRECT(CONCATENATE(A1,"!A1")))+1
    If their names were in cells A2-An+1 in the class sheet, then their names could be listed in cell C1
    =INDIRECT(CONCATENATE(A1,"!",B1+1))
    Copy cell A1 27 times down the column, you will have 27 random names. This will probably return the same name more than one time, so you could make more than 27 copies and remove the duplicates yourself.

    If you want to generate a unique set of names automatically, you will have to go the macro route.

  3. #3
    Registered User
    Join Date
    03-02-2009
    Location
    St Ives
    MS-Off Ver
    Excel 2003
    Posts
    2

    Smile Re: Random Selections

    I will give that a try, but we do need the selections to be unique, plus this would not be the only time we nedd to do this. So I gues its down the macro route then. Any ideas how this could be done.
    Again thanks in advance

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Random Selections

    attached will give 27 or whatever unique students randomly selected from sheets 1-10
    on tab generate
    f9 to re calc, allows for each class max 40 pupils but you could adjust as you need .
    requires that analysis tool pack add in activated as it uses the randbetween function
    Attached Files Attached Files
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Random Selections

    Great! I didn't know about the randbetween function!

+ 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