+ Reply to Thread
Results 1 to 10 of 10

RANDomly select from list IF criteria is met

  1. #1
    Registered User
    Join Date
    12-29-2015
    Location
    Edmonton, Alberta
    MS-Off Ver
    Professional Plus 2010
    Posts
    5

    RANDomly select from list IF criteria is met

    Hello,

    I have been trying to come up with a formula that will randomly select names (from column B) if they have passed (in column D), generating a list (column F) of students that will be tested next.
    Basically, if someone in coloumn B shows PASS in column D they can be ignored. If the users have failed or not taken the test, I would like them to be included in my random selection.
    All the formulas I have tried will either give me an error, or a name that I wanted excluded...

    =IF(D2="PASS", "Passed", INDEX(B2:B15, RAND()*COUNTA(B2:B15),0))

    I have attached a very small sample of what I mean. I actually have thousands of names, which is making this formula business very frustrating. Hopefully someone can shed some light on my IF RAND & INDEX function...
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: RANDomly select from list IF criteria is met

    Try

    =IF(D2="PASS","Passed",INDEX(B2:B15,RAND()*COUNTIF(D2:D15,"<>PASS")))

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: RANDomly select from list IF criteria is met

    There isn't really an efficient way to randomise a list with formula. See if this helps.

    In E2 and fill down to the last row of data, hide the column if desired.

    =IF(D2<>"PASS",RAND(),"")

    In F2 and filled down as required to generate the names for the test group.

    =IFERROR(INDEX(B:B,MATCH(SMALL(E:E,ROWS(F$2:F2)),E:E,0)),"")

  4. #4
    Registered User
    Join Date
    12-29-2015
    Location
    Edmonton, Alberta
    MS-Off Ver
    Professional Plus 2010
    Posts
    5

    Re: RANDomly select from list IF criteria is met

    JohnTopley =IF(D2="PASS","Passed",INDEX(B2:B15,RAND()*COUNTIF(D2:D15,"<>PASS")))
    I tried this formula in the sample data and it pulled a name that passed, as well it has several 0
    I think I have screwed up the formula in the beginning with IF(D2="Pass"...
    How do I say in excel -> if column D in row says "Pass", ignore name from selection ?
    I think i need an array in the formula

  5. #5
    Registered User
    Join Date
    12-29-2015
    Location
    Edmonton, Alberta
    MS-Off Ver
    Professional Plus 2010
    Posts
    5

    Re: RANDomly select from list IF criteria is met

    jason.b75 =IF(D2<>"PASS",RAND(),"") & =IFERROR(INDEX(B:B,MATCH(SMALL(E:E,ROWS(F$2:F2)),E:E,0)),"")

    I also tried this method - the amounts in column E are decimal numbers (weird?)
    This did however eliminate any of those that PASS from being chosen in column F
    Is there any possible way to combine these formulas?
    Thank you for your help, at least I have a back up plan if I cant find a 'one step' formula

  6. #6
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: RANDomly select from list IF criteria is met

    You will never do it with a single column formula, you need a separate column to generate the random values.

    Each random value needs to be passed to the INDEX formula twice, one to assign the random value to the relevant row of data in the source table, then again to rank that value against the others.

    Entering the RAND function twice in the same formula will not assign the same random value both times, so the current record can't even be compared to itself for ranking purposes, considering that you then have to perform the same task, which cannot be done, for each row in the table / array, you are effectively attempting impossible to the power of infinity.

    Using a helper column for the random values maintains consistency for the current calculation cycle, providing the INDEX function with the comparable values it needs to effectively rank the results.

  7. #7
    Registered User
    Join Date
    12-29-2015
    Location
    Edmonton, Alberta
    MS-Off Ver
    Professional Plus 2010
    Posts
    5

    Re: RANDomly select from list IF criteria is met

    Thank you for the explanation jason.b75 (easy to follow, difficult to understand)

    While I was testing your formula I've discovered that I should change my thinking...
    Rather than ignoring anyone that PASSED, I actually need to select from only those with TBD status
    The reason for this is that all FAIL will be selected for retest immediately (which I can easily filter from the list), while only a portion of the TBD will be selected at a time

    Should that change the original formula in coloumn E from =IF(D2<>"PASS",RAND(),"") to the new column E formula =IF(D2="TBD",RAND(),"") ?

  8. #8
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: RANDomly select from list IF criteria is met

    Yes, that is the correct change to the formula.

    YOU could go one better and use

    =IF(D2=$Z$99,RAND(),"")

    Then you could enter TBD or FAIL in Z99 (or any suitable cell), depending on which group you want to pull names from, that way you only have to change 1 cell instead of a whole column of formula.

    If you wanted to assign proportionate groups, say 20 TBD and 10 FAIL per group, then I'm sure we could find a way.
    Last edited by jason.b75; 12-29-2015 at 07:29 PM.

  9. #9
    Registered User
    Join Date
    12-29-2015
    Location
    Edmonton, Alberta
    MS-Off Ver
    Professional Plus 2010
    Posts
    5

    Re: RANDomly select from list IF criteria is met

    I just wanted to come back and let you know that this formula is working well for me - Thank you in abundance!
    I had to add the extra column to my worksheet (to assign random values) - maybe if I was more willing to do this in two steps from the beginning I wouldn't have ended up so confused.


    I have a really easy question for you. List of 100 names (shown in A), we want to review 10% of them (create list in B)
    I was using this formula (in B)
    =INDEX($A$2:$A100, ROUND(RAND()*COUNTA($A$2:$A$100),0))
    But this results in duplicate names generated in column B. I currently use the Remove Duplicates tool after getting the random list of names.
    Do you have a better formula for this (that would eliminate duplicates and my extra step)?

    I got the formula from the internet (after struggling on my own), so I honestly don't know how effective =INDEX($A$2:$A100, ROUND(RAND()*COUNTA($A$2:$A$100),0)) actually is.

    Thanks again
    Last edited by Framci; 12-30-2015 at 05:04 PM.

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: RANDomly select from list IF criteria is met

    You could adopt Jason's method of having a column filled using RAND() then use ..

    =INDEX($A$2:$A$101,MATCH(SMALL($B$2:$B$101,ROWS($1:1)),$B$2:$B$101,0))

    and drag down 10 rows

    Column B (but select any column and hide if required) has =RAND() and the above formula is in column C (rows 2 to 11)

+ 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. [SOLVED] Randomly select 25% of list and copy to new tab
    By fatboyzfishing in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-14-2023, 08:31 PM
  2. [SOLVED] Randomly select one of two cells to populate from a list
    By 90Shilling in forum Excel General
    Replies: 1
    Last Post: 10-17-2013, 12:04 PM
  3. [SOLVED] if restriction is not met, select another word randomly from the list
    By bloem in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 07-11-2013, 10:52 AM
  4. [SOLVED] Code to randomly select from a list based on Cell text value inptted
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-20-2013, 05:57 PM
  5. Randomly select from long list
    By Lifeseeker in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-17-2011, 08:08 PM
  6. Select rows randomly
    By freaksareus in forum Excel General
    Replies: 2
    Last Post: 12-02-2009, 10:04 AM
  7. How to randomly select from a list with condition
    By kathyxyz in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-27-2005, 11:19 AM

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