+ Reply to Thread
Results 1 to 12 of 12

How To Lookup The 2nd last matching value?

  1. #1
    Forum Contributor
    Join Date
    01-07-2012
    Location
    Ontario
    MS-Off Ver
    365
    Posts
    157

    How To Lookup The 2nd last matching value?

    Hi All,

    I used this example from google to find out how to return the last matching value from a list but I want to return the second last value from the list instead and I am not sure what adjustment I need to do.

    What formula can I enter in E2 so that the value returns 65 instead?

    Many thanks!
    Attached Files Attached Files
    Last edited by PaddyP; 08-07-2021 at 04:54 PM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: How To Lookup The 2nd last matching value?

    try

    =INDEX($B$2:$B$8,AGGREGATE(15,6,ROW(A1:A8)/($A$2:$A$8=$D$2),COUNTIF($A$2:A$8,D$2)-1))

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: How To Lookup The 2nd last matching value?

    @John: works ok when there are two or more options to choose from but fails if there is only one option. But easy to fix with an IFERROR( … , INDEX/MATCH( … ))

    Well done though, I wouldn't know where to start with this problem/solution.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Contributor
    Join Date
    01-07-2012
    Location
    Ontario
    MS-Off Ver
    365
    Posts
    157

    Re: How To Lookup The 2nd last matching value?

    Thanks for the solution John.

    My real data is actually on two different sheets and has two blank cells above the list. See new template.

    Can you help me adjust the formula given the new cell locations please?
    Attached Files Attached Files

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: How To Lookup The 2nd last matching value?

    Try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: How To Lookup The 2nd last matching value?

    With the revision …

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by TMS; 08-07-2021 at 04:06 PM.

  7. #7
    Forum Contributor
    Join Date
    01-07-2012
    Location
    Ontario
    MS-Off Ver
    365
    Posts
    157

    Re: How To Lookup The 2nd last matching value?

    Thanks but I moved the ranges around so this isn't working.

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: How To Lookup The 2nd last matching value?

    fyi; with only one entry

    =INDEX($B$2:$B$8,AGGREGATE(15,6,ROW(A1:A8)/($A$2:$A$8=$D$2),MAX(COUNTIF($A$2:A$8,D$2)-1,1)))

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: How To Lookup The 2nd last matching value?

    try

    =INDEX(Sheet1!$F$4:$F$100,AGGREGATE(15,6,(ROW($A$4:$A$100)-ROW($A$4)+1)/(Sheet1!$E$4:$E$100=$A$2),MAX(COUNTIF(Sheet1!$E$4:$E$100,$A$2)-1,1)))

  10. #10
    Forum Contributor
    Join Date
    01-07-2012
    Location
    Ontario
    MS-Off Ver
    365
    Posts
    157

    Re: How To Lookup The 2nd last matching value?

    John this last revision works to perfection. Thank you!

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: How To Lookup The 2nd last matching value?

    You're welcome and thank you for the rep.

  12. #12
    Forum Expert wk9128's Avatar
    Join Date
    08-15-2020
    Location
    Australia
    MS-Off Ver
    365 V2403 and WPS V2022
    Posts
    3,427

    Re: How To Lookup The 2nd last matching value?

    Ans Post#1
    Cell E2 formula

    HTML Code: 
    Ans Post#4
    worksheet name : Sheet2
    Cell D2 formula
    HTML Code: 

+ 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. LOOKUP a matching value
    By imranhabib01 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 06-15-2021, 07:23 AM
  2. [SOLVED] Lookup not matching
    By pauldaddyadams in forum Excel General
    Replies: 3
    Last Post: 08-22-2014, 05:57 AM
  3. [SOLVED] Lookup question matching part of lookup value in the table array
    By kosmo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-05-2013, 11:07 AM
  4. Need Help LOOKUP MATCHING
    By Hellobuck2013 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-05-2013, 06:28 PM
  5. Lookup matching value
    By Montoro22 in forum Excel General
    Replies: 3
    Last Post: 07-17-2012, 03:04 PM
  6. Lookup or Matching
    By jayclinton in forum Excel General
    Replies: 4
    Last Post: 11-22-2010, 09:57 PM
  7. RE: matching and lookup??
    By Duke Carey in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-10-2005, 05:00 PM

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