+ Reply to Thread
Results 1 to 12 of 12

Return a number from a range of cells based on criteria?

  1. #1
    Forum Contributor
    Join Date
    08-17-2010
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    127

    Return a number from a range of cells based on criteria?

    A1= 2
    A2 = 4
    A3 = 6


    B1 = 3

    C1 = has to look through A1, A2, A3 and return the closest larger number (in comparison to B1's 3), in that case return A2 with its 4.
    D1 = Needs to do the same thing but return the cell with the closest lower number - in this case A1.

    I don't even have an idea how to craft a usable search term for this.
    Last edited by Polymorpher; 07-25-2014 at 08:14 AM.

  2. #2
    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: Return a number from a range of cells based on criteria?

    Try this array formula

    =MIN(IF(A1:A3>B1,A1:A3))

    and to return number lower than B1

    =MIN(IF(A1:A3<B1,A1:A3))

    ...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
    B
    C
    D
    1
    2
    3
    4
    2
    2
    4
    3
    6
    Last edited by AlKey; 07-25-2014 at 08:34 AM.
    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

  3. #3
    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: Return a number from a range of cells based on criteria?

    Thank you for the feedback!

    Please mark thread as "Solved" if your issue has been resolved. (Selecting Thread Tools -> Mark thread as Solved).

  4. #4
    Forum Contributor
    Join Date
    08-17-2010
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    127

    Re: Return a number from a range of cells based on criteria?

    you have to use MAX on one of them for some reason. don't know the reason - was just speculating when it broke down (;

  5. #5
    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: Return a number from a range of cells based on criteria?

    Quote Originally Posted by Polymorpher View Post
    you have to use MAX on one of them for some reason. don't know the reason - was just speculating when it broke down (;
    Do you care to explain why?

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Return a number from a range of cells based on criteria?

    Quote Originally Posted by AlKey View Post
    Do you care to explain why?
    For the closest number that is less than the target number...

    =MIN(IF(A1:A3<B1,A1:A3))
    That should be:

    =MAX(IF(A1:A3<B1,A1:A3))

    Also, may need to account for instances if/when there are no values that meet the condition otherwise the formulas will return 0 which may be a misleading result.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    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: Return a number from a range of cells based on criteria?

    @Tony,

    Isn't this is the same formula that I already provided?

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Return a number from a range of cells based on criteria?

    Quote Originally Posted by AlKey View Post
    @Tony,

    Isn't this is the same formula that I already provided?
    No. You used MIN for both conditions...

    Quote Originally Posted by AlKey View Post
    Try this array formula

    =MIN(IF(A1:A3>B1,A1:A3))

    and to return number lower than B1

    =MIN(IF(A1:A3<B1,A1:A3))

  9. #9
    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: Return a number from a range of cells based on criteria?

    One is > than B1 and the other is < than B1
    the =MAX(IF(A1:A3<B1,A1:A3)) can be used for the second condition but the result is the same as with =MIN(IF(A1:A3<B1,A1:A3))

  10. #10
    Forum Contributor
    Join Date
    08-17-2010
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    127

    Re: Return a number from a range of cells based on criteria?

    It fails at some point... Don't ask me why. (perhaps because I'm constantly changing B1)

    Even before i make it into something like this

    =MAX(IF(C8:C21<=H13,OFFSET(C8:C21,-1,1)))
    Last edited by Polymorpher; 07-25-2014 at 11:00 AM.

  11. #11
    Forum Contributor
    Join Date
    08-17-2010
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    127

    Re: Return a number from a range of cells based on criteria?

    Its some mathematical symmetry no doubt, thats what lead me to see if there is a MAX function and try it ...
    Last edited by Polymorpher; 07-25-2014 at 11:06 AM.

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Return a number from a range of cells based on criteria?

    Quote Originally Posted by AlKey View Post
    One is > than B1 and the other is < than B1
    the =MAX(IF(A1:A3<B1,A1:A3)) can be used for the second condition but the result is the same as with =MIN(IF(A1:A3<B1,A1:A3))
    Yes, based on the very limited sample posted by the OP, but it returns an incorrect result on a larger range of numbers.

    I'm guessing the OP has more than a 3 number range to compare. That's why they said:

    you have to use MAX on one of them for some reason. don't know the reason - was just speculating when it broke down

+ 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: 4
    Last Post: 06-13-2014, 07:08 PM
  2. [SOLVED] Return Column Number Based On Multiple Criteria
    By taccoo73 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-17-2014, 10:03 PM
  3. Trying to get single data return from a range based on 3 criteria
    By alycat75 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2012, 10:26 AM
  4. return all range based on criteria
    By Dumy in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 07-28-2011, 04:21 AM
  5. [SOLVED] Return number OR sum based on two criteria
    By John in MN in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-26-2006, 09:25 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