+ Reply to Thread
Results 1 to 10 of 10

How to find first cell in range greater than X, if there is such a cell?

  1. #1
    Registered User
    Join Date
    03-25-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    61

    How to find first cell in range greater than X, if there is such a cell?

    Howdy Excel Brainiacs!

    I need a formula that looks at a range of rows (say, A10:A100) and finds the first cell with a value greater than X. I need to identify the cell address, not the value in the cell! If there is no such cell, then it can return some other value.

    Seems like it should be easy, but I've been at it for hours trying to use various combinations of VLOOKUP and MAX and ADDRESS and SEARCH and INDIRECT, and I just can't make it work!

    Can anyone help?


    Thanks!
    Last edited by hadamhiram; 03-25-2013 at 10:55 PM. Reason: SOLVED

  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: How to find first cell in range greater than X, if there is such a cell?

    =ADDRESS(MATCH(TRUE,INDEX(A10:A100>A1,0),0)+9,1) where a1 has your value X
    or
    =IF(ISERROR(MATCH(TRUE,INDEX(A10:A100>A3,0),0)),"some message",ADDRESS(MATCH(TRUE,INDEX(A10:A100>A3,0),0)+9,1))
    "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
    03-25-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: How to find first cell in range greater than X, if there is such a cell?

    Thanks for your help! But I must be a dummy - I can't quite get either of those formulas to work .

    Even when the conditions are true, the address returned is always the same - $A$12. When I try changing the Address function parameters, I just get #N/A... not sure what I'm doing wrong.

    Thanks again!


    EDIT: I think I've figured out how the MATCH portion of the function works, but I'm still struggling to use ADDRESS to turn its output into a cell reference all within the same formula ...
    Last edited by hadamhiram; 03-25-2013 at 10:08 PM.

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

    Re: How to find first cell in range greater than X, if there is such a cell?

    Here's another one...

    A1 = X value

    Array entered**:

    =IF(COUNTIF(A10:A100,">"&A1),ADDRESS(MATCH(TRUE,A10:A100>A1,0)+ROW(A10)-1,1,4),"NA")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

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

    Re: How to find first cell in range greater than X, if there is such a cell?

    =ADDRESS(MATCH(TRUE,INDEX(A10:A100>A1,0),0)+9,1) where a1 has your value X
    or
    =IF(ISERROR(MATCH(TRUE,INDEX(A10:A100>A1,0),0)),"some message",ADDRESS(MATCH(TRUE,INDEX(A10:A100>A1,0),0)+9,1)) typo there by me
    you might want
    =IF(A1="","",ADDRESS(MATCH(TRUE,INDEX(A10:A100>A1,0),0)+9,1))
    or
    =IF(A1="","",IF(ISERROR(MATCH(TRUE,INDEX(A10:A100>A1,0),0)),"some message",ADDRESS(MATCH(TRUE,INDEX(A10:A100>A1,0),0)+9,1))) in case you want no return when a1 is blank
    Attached Files Attached Files
    Last edited by martindwilson; 03-25-2013 at 10:18 PM.

  6. #6
    Registered User
    Join Date
    03-25-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: How to find first cell in range greater than X, if there is such a cell?

    Fantastic - I got it to work, and I understand it too!

    Thank you so you much for your help!

  7. #7
    Registered User
    Join Date
    05-18-2012
    Location
    London
    MS-Off Ver
    2013
    Posts
    14

    Re: How to find first cell in range greater than X, if there is such a cell?

    Sorry for bringing up an old thread, but the following formula works perfectly!
    =MATCH(TRUE,INDEX(A10:A100>A1,0),0) where A1 has your value X

    What I can't seem to understand is the logic behind "A10:A100>A1" in the INDEX formula. I can't seem to find any official documentation explaining the logic behind using a > operator. Could someone explain the logic behind this formula? On using the INDEX formula by itself, it results in FALSE which doesn't make any sense!

    Thanks!

  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: How to find first cell in range greater than X, if there is such a cell?

    Let's assume this is the data:

    Data Range
    A
    B
    C
    1
    61
    3
    2
    3
    12
    4
    23
    5
    65
    6
    10
    7
    2
    8
    ------
    ------
    ------


    This formula entered in C1:

    =MATCH(TRUE,INDEX(A3:A7>A1,0),0)

    The INDEX function generates an array of TRUE or FALSE values from this logical test:

    A3:A7>A1

    The individual elements of the array are:

    A3 > A1 = 12 greater than 61 = FALSE
    A4 > A1 = 23 greater than 61 = FALSE
    A5 > A1 = 65 greater than 61 = TRUE
    A6 > A1 = 10 greater than 61 = FALSE
    A7 > A1 = 2 greater than 61 = FALSE

    Now we have:

    =MATCH(TRUE,{FALSE;FALSE;TRUE;FALSE;FALSE},0)

    The lookup value TRUE is found at the 3rd element of the array {FALSE;FALSE;TRUE;FALSE;FALSE}

    So:

    =MATCH(TRUE,INDEX(A3:A7>A1,0),0)

    =3

  9. #9
    Registered User
    Join Date
    05-18-2012
    Location
    London
    MS-Off Ver
    2013
    Posts
    14

    Re: How to find first cell in range greater than X, if there is such a cell?

    Wow! Thanks for taking the time to explain Tony. It's perfectly clear now. Previously, since I was only looking at the cell where the index formula so I didn't realise it was a true/false array!

    Much appreciated!

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

    Re: How to find first cell in range greater than X, if there is such a cell?

    You're welcome. Thanks for the feedback!

+ 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