Closed Thread
Results 1 to 13 of 13

work up to find next number not 0

  1. #1
    Registered User
    Join Date
    08-07-2013
    Location
    maryport
    MS-Off Ver
    Excel 2013
    Posts
    54

    Post work up to find next number not 0

    hey guys,

    i have a problem. im looking for a formula that finds the last number entered in a column that isnt 0. for example, a1-a10 are numbers. a7,8,9 and 10 contains 0. the other 6 contain values higher than 0. I would like a formula to start at a10 and work upwards then display a6.

    anyone??

    thanks

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

    Re: work up to find next number not 0

    Data Range
    A
    B
    C
    1
    2
    63
    57
    3
    0
    4
    68
    5
    0
    6
    95
    7
    57
    8
    0
    9
    0
    10
    0

    Try ths...

    =LOOKUP(2,1/(A2:A10<>0),A2:A10)
    Last edited by Tony Valko; 09-09-2013 at 10:02 AM.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: work up to find next number not 0

    Try

    =LOOKUP(2,1/(A1:A10),A1:A10)

  4. #4
    Registered User
    Join Date
    08-07-2013
    Location
    maryport
    MS-Off Ver
    Excel 2013
    Posts
    54

    Re: work up to find next number not 0

    works like a charm, thanks! i dont suppose an explanation of the formula is possible?? i just like to understand why it works for future use

  5. #5
    Registered User
    Join Date
    08-07-2013
    Location
    maryport
    MS-Off Ver
    Excel 2013
    Posts
    54

    Re: work up to find next number not 0

    just noticed, if all cells are 0 it brings up the ugly #N/A error, anyone know how to fix this? i'd like it so if there is no value at all just dont display anything...

  6. #6
    Registered User
    Join Date
    08-07-2013
    Location
    maryport
    MS-Off Ver
    Excel 2013
    Posts
    54

    Re: work up to find next number not 0

    nevermind, used the iserror, thanks again!

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

    Re: work up to find next number not 0

    Let's use this example to demonstrate how this works:

    Data Range
    A
    B
    C
    1
    2
    63
    57
    3
    0
    4
    68
    5
    0
    6
    95
    7
    57
    8
    0
    9
    0
    10
    0

    Return the bottom-most non-zero number in column A.

    =LOOKUP(2,1/(A2:A10<>0),A2:A10)

    This expression will return an array of either TRUE or FALSE:

    (A2:A10<>0)

    <> means: not equal to. I think it's easier to understand if you read it as: "is not". A2:A10 is not 0

    A2 = 63 <> 0 = TRUE
    A3 = 0 <> 0 = FALSE
    A4 = 68 <> 0 = TRUE
    A5 = 0 <> 0 = FALSE
    A6 = 95 <> 0 = TRUE
    A7 = 57 <> 0 = TRUE
    A8 = 0 <> 0 = FALSE
    A9 = 0 <> 0 = FALSE
    A10 = 0 <> 0 =FALSE

    We then use the divison operation to coerce those logical values to numbers:

    A2 = 1 / TRUE = 1
    A3 = 1 / FALSE = #DIV/0!
    A4 = 1 / TRUE = 1
    A5 = 1 / FALSE = #DIV/0!
    A6 = 1 / TRUE = 1
    A7 = 1 / TRUE = 1
    A8 = 1 / FALSE = #DIV/0!
    A9 = 1 / FALSE = #DIV/0!
    A10 = 1 / FALSE = #DIV/0!

    At this point the formula looks like this:

    =LOOKUP(2,{1;#DIV/0!;1;#DIV/0!;1;1;#DIV/0!;#DIV/0!;#DIV/0!),A2:A10)

    The way that LOOKUP works is if the lookup_value is greater than all the
    values in the lookup_vector it will match the *last* value in the
    lookup_vector. So, we simply need a lookup_value that is greater than any number in the lookup_vector.

    We use a lookup_value of 2 because we know that the result of this expression:

    1/(A2:A10<>0)

    will not return a value greater than 1. Therefore, the lookup_value 2 is guaranteed to be greater than all the 1s in the lookup_vector.

    The *last* numeric value in the lookup_vector is the 4th 1. The #DIV/0! errors are ignored (unless there are ALL errors).

    This is how that would look:

    Data Range
    A
    2
    1
    3
    #DIV/0!
    4
    1
    5
    #DIV/0!
    6
    1
    7
    1
    8
    #DIV/0!
    9
    #DIV/0!
    10
    #DIV/0!

    So, the last (bottom-most) instance of a non-zero number was in A7.

    Data Range
    A
    B
    C
    1
    2
    63
    57
    3
    0
    4
    68
    5
    0
    6
    95
    7
    57
    8
    0
    9
    0
    10
    0

    =LOOKUP(2,1/(A2:A10<>0),A2:A10) = 57
    Last edited by Tony Valko; 09-09-2013 at 10:53 AM.

  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: work up to find next number not 0

    Use IFERROR:

    =IFERROR(LOOKUP(2,1/(A2:A10<>0),A2:A10),"")

  9. #9
    Forum Contributor
    Join Date
    07-02-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    197

    Re: work up to find next number not 0

    Quote Originally Posted by Tony Valko View Post

    =LOOKUP(2,1/(A2:A10<>0),A2:A10)
    When I try your formula the answer is 0 (zero). But if I take the <>0 away it gives 57 as result.

  10. #10
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: work up to find next number not 0

    Quote Originally Posted by Rambo4711 View Post
    When I try your formula the answer is 0 (zero). But if I take the <>0 away it gives 57 as result.
    Your blanks are probably not really blanks.
    Are they formulas that return "" ?

    Try this instead
    =LOOKUP(2,1/((A2:A10<>0)*(A2:A10<>"")),A2:A10)

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

    Re: work up to find next number not 0

    Actually, the formula will work either way:

    =LOOKUP(2,1/(A2:A10<>0),A2:A10)
    =LOOKUP(2,1/(A2:A10),A2:A10)

    The <>0 version gives you more info as to what the criteria is.

    Also, it is assumed that the range does not contain any text entries, numbers only.
    Last edited by Tony Valko; 09-09-2013 at 11:08 AM.

  12. #12
    Registered User
    Join Date
    09-28-2018
    Location
    Neumarkt, Germany
    MS-Off Ver
    Office 365
    Posts
    6

    Re: work up to find next number not 0

    Hi,

    how can i combine that with XLOOKUP?

    For example i want to find the value of "k" that is not zero (57). I had the following formula, but it gives me an error:
    =+LOOKUP(2;1/(XLOOKUP("k";A:A;B:B)<>0);XLOOKUP("k";A:A;B:B))


    - A B
    1 a
    2 b 63
    3 c 0
    4 d 68
    5 e 0
    6 k 0
    7 k 0
    8 k 57
    9 k 0
    10 k 0

    Thank you!
    Attached Images Attached Images
    Last edited by marianacollier; 08-22-2023 at 05:04 AM.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,933

    Re: work up to find next number not 0

    Administrative Note:

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Find match, find related cell and return that number
    By HelpHelpHelp in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-17-2012, 06:46 AM
  2. Find highest number of sales in a date range and show seller and sale number
    By audiofreak in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-06-2012, 03:34 AM
  3. [SOLVED] To find any 4 digit number and return the same number with desired formating effect.
    By neo4u44 in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2012, 12:45 AM
  4. Replies: 7
    Last Post: 12-18-2008, 07:34 PM
  5. [SOLVED] Find formatting doesn't work: "Excel cannot find data"
    By Kasama in forum Excel General
    Replies: 1
    Last Post: 08-18-2006, 08:45 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