+ Reply to Thread
Results 1 to 15 of 15

Return second to last non blank cell

  1. #1
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Return second to last non blank cell

    Good morning all and Happy New Year!

    I have a column of figures and want to return the last non-blank cell value, and second-to-last non-blank value.

    The first part was easy enough to resolve using:

    =LOOKUP(2,1/B5:B35,B5:B35)

    Now, silly me, but I thought using an offset function would be a simple was of returning the second-to-last value. However, when I attempted to incorporate it into my original formula:

    =OFFSET(LOOKUP(2,1/B5:B35,B5:B35),-1,0)

    I get the 'the formula you entered contains an error' message. Am I missing something really obvious here?

    Thanks

    Steve
    Last edited by SAsplin; 01-04-2013 at 05:11 AM.

  2. #2
    Forum Contributor
    Join Date
    11-07-2012
    Location
    .
    MS-Off Ver
    2003 - 2013 for Windows
    Posts
    121

    Re: Return second to last non blank cell

    Hello,

    the lookup function does not return a cell address, but the contents of the cell. That cannot be used as a parameter for the Offset function. Instead of the Lookup, you could use an Index/Match combo like this

    =INDEX(B5:B35,MATCH(99^99,B5:B35,1))

    Then you can easily manipulate the Match part to return one row above the match:

    =INDEX(B5:B35,MATCH(99^99,B5:B35,1)-1)
    regards, LMP

  3. #3
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Return second to last non blank cell

    Maybe

    =LOOKUP(99^99,INDIRECT("B5:"&ADDRESS(MATCH(99^99,B:B)-1,2)))
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  4. #4
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Return second to last non blank cell

    Thanks guys for your quick responses. Imp - your solution for the second-to-last value works perfectly. I thought I was pretty handy with a formula - goes to show you can learn something new every day!

    Have a great New Year!

    Steve

  5. #5
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Return second to last non blank cell

    The only problem with the nice lmp's suggestion is if there are empty cells in the range.

    A Non-Volatile version hich replaces INDIRECT is this.

    =LOOKUP(9.99E+307,B5:INDEX(B:B,MATCH(9.99E+307,B:B)-1))

  6. #6
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Return second to last non blank cell

    Fotis - thanks for the alternative. How does that work? 9.99E+307?

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,786

    Re: Return second to last non blank cell

    how about just changing the second range in the original ?

    =LOOKUP(2,1/B5:B35,B4:B34)
    Audere est facere

  8. #8
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Return second to last non blank cell

    It's the largest number that Excel can store, Steve. This "Big number" is used to look up the last number in a range. Do a simple Google search and you'll find more details for this.

    You are welcome and thanks for the reb*

  9. #9
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Return second to last non blank cell

    Quote Originally Posted by daddylonglegs View Post
    how about just changing the second range in the original ?

    =LOOKUP(2,1/B5:B35,B4:B34)
    I think that this formula also has problem with empty cells, Teacher.

    Example: B9= Last number in the range. B8= Empty, B7=Number.

    This formula, gives 0

  10. #10
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Return second to last non blank cell

    Well, one way or the other you've definitely solved my query! Thanks again everyone.

  11. #11
    Forum Contributor Big.Moe's Avatar
    Join Date
    03-15-2012
    Location
    Corea, Maine, USA
    MS-Off Ver
    Excel 2010
    Posts
    262

    Re: Return second to last non blank cell

    Quote Originally Posted by Fotis1991 View Post
    The only problem with the nice lmp's suggestion is if there are empty cells in the range.

    A Non-Volatile version hich replaces INDIRECT is this.

    =LOOKUP(9.99E+307,B5:INDEX(B:B,MATCH(9.99E+307,B:B)-1))
    Hello Folks,
    Sorry to dig-up a moldy oldie for you, but I'm trying to use Fortis1991's formula in my spreadsheet and coming across an error.

    In the attached spreadsheet, in tab "Jan" - cell K46, the formula works perfectly, returning the 2nd non-blank value from the bottom in K24.

    However, in tab "Mar" - cell K46, the formula skips the 2nd non-blank value from the bottom in cell K33, and incorrectly returns the 3rd non-blank value in K27.

    Any help or ideas would be greatly appreciated.
    Attached Files Attached Files

  12. #12
    Forum Contributor Big.Moe's Avatar
    Join Date
    03-15-2012
    Location
    Corea, Maine, USA
    MS-Off Ver
    Excel 2010
    Posts
    262

    Re: Return second to last non blank cell

    As it turns out, I solved my own question.
    Well, actually Rick Rothstein (moderator in Mr. Excel forum) solved my problem with a similar thread back in 2011.

    He came up with this formula:
    Please Login or Register  to view this content.
    Which I revised for my own use as such:
    Please Login or Register  to view this content.
    Last edited by Big.Moe; 09-29-2019 at 01:46 PM.

  13. #13
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Return second to last non blank cell

    Hi Big.Moe,

    Glad you found your solution, but for future references.

    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
    HTH
    Regards, Jeff

  14. #14
    Forum Contributor Big.Moe's Avatar
    Join Date
    03-15-2012
    Location
    Corea, Maine, USA
    MS-Off Ver
    Excel 2010
    Posts
    262

    Re: Return second to last non blank cell

    My apologies. I can see how digging-up an old thread can make things confusing.

  15. #15
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Return second to last non blank cell

    No worries.

    The two moderators on this thread are rather infrequent on their visits to the forum lately.

+ 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