+ Reply to Thread
Results 1 to 3 of 3

Randomly selecting items from list under certain conditions

  1. #1
    Registered User
    Join Date
    12-06-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    2

    Randomly selecting items from list under certain conditions

    Alright, this problem has been annoying me for the past 3 hours or so
    I had to create a new account on here for help!

    Basically I want a formula that will randomly select foods that are under a specific amount of calories and return the value as a randomly selected food which has an amount of calories that are under the specified amount

    This is what I got so far:

    INDEX(Recipes!E11:F20,MATCH(RANDBETWEEN(37,D18),Recipes!F11:F20,1),1)

    Recipes!E11:F20 is the list of foods in E with the calories of them in F
    Recipes!F11:F20 are the calories of the foods
    D18 is the value that I want the formula to search for foods under

    All this formula does is return around 4 foods, when its supposed to return more...

    Please help!

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

    Re: Randomly selecting items from list under certain conditions

    MATCH(RANDBETWEEN(37,D18),Recipes!F11:F20,1),will find the largest value less than or = to look up and the values must be sorted ascending or youll get the sort of results you are experiencing.
    try inserting another column say g and put =if(recipies!f11<$d$18,rand(),0)
    then use
    INDEX(Recipes!E11:e20,MATCH(max(Recipes!g11:g20),Recipes!g11:g20,0))
    "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

  3. #3
    Registered User
    Join Date
    12-06-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Randomly selecting items from list under certain conditions

    Aha, thanks martindwilson!

    I just needed to sort it out in ascending order, stupid me!
    It all works perfectly fine now

+ 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