+ Reply to Thread
Results 1 to 4 of 4

Formula to return position of the last non-blank cell

  1. #1
    Registered User
    Join Date
    05-16-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    23

    Formula to return position of the last non-blank cell

    I need to retreive the value of the last non-blank cell in a row and the value juste above it.

    For the value of the last non-blank cell I'm using this formula: =LOOKUP(2;1/(Sheet1!E73:DV73<>"");Sheet1!E73:DV73)

    The formula works well but I don't really understand why. I found it in the following thread:

    http://www.excelforum.com/excel-gene...-in-range.html

    Now I need the value of the cell juste above. I thought I would retrieve the position of the last non-blank cell as found in the previous exemple and then use a match-index combination to get the value one row higher but I can't find a way to do it. Probably because I don't really get the first formula I'm using.

    Any ideas?

  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: Formula to return position of the last non-blank cell

    =LOOKUP(2;1/(Sheet1!E73:DV73<>"");Sheet1!E72:DV72) would do it
    fyi how it works
    =LOOKUP(2;1/(Sheet1!a2:e2<>"");Sheet1!a1:e1)
    and in a2 to e2 you have
    something blank something blank something
    Sheet1!a2:e2<>"" gives an array of {1;0;1;0;1}
    now when the reciprocal of the range is calculated
    1/(Sheet1!a2:e2<>"")
    returns an array of {1;#DIV/0!;1;#DIV/0!;1}
    lookup() conveniently ignores error values (i dont know why its a quirk and just does!)
    also if lookup cannot find a match in this case we are looking for 2
    =LOOKUP(2;1/(Sheet1!a2:e2<>"");Sheet1!a1:e1)
    ie lookup(2;{1;#DIV/0!;1;#DIV/0!;1};Sheet1!a1:e1)
    then from the help files
    If LOOKUP can't find the lookup_value, it matches the largest value in lookup_vector that is less than or equal to lookup_value.
    what it doesn't say is if all are the same or less it takes the last one from the array
    so in this case it finds the last 1 in the array
    {1;#DIV/0!;1;#DIV/0!;1}
    which happens to be position 5
    it then returns the value in the corresponding position from the second array
    Sheet1!a1:e1
    ie the value in e1
    hth
    Last edited by martindwilson; 07-10-2013 at 06:41 AM.
    "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
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Formula to return position of the last non-blank cell

    try:

    Please Login or Register  to view this content.
    - i.s.z -
    CSE, aka Array aka { }, formulae are confirmed with CONTROL+SHIFT+ENTER.
    Replace commas ( , ) with semicolons ( ; ) in formulae, if your locale setting demands.
    All good ideas are courtesy resources from this forum as well as others around the web.
    - e.o.m -

  4. #4
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Formula to return position of the last non-blank cell

    One more approach..

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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