+ Reply to Thread
Results 1 to 5 of 5

Use vlookup to return first and last-but-one values

  1. #1
    Registered User
    Join Date
    03-30-2018
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    1

    Use vlookup to return first and last-but-one values

    I have a list of names with a variable number of occurrences identified by year, and for each name a total (of other columns) record:

    NameA 1960
    NameA 1961
    NameA Total
    NameB 2004
    NameB 2005
    NameB 2006
    NameB Total
    NameC 1957
    NameC 1960
    NameC 1964
    NameC Total
    NameD 2018
    NameD Total

    I want to report separately the first year for each unique name listed elsewhere (easy, using vlookup) and the last year for each name.

    This I am having a problem with and cannot find a solution within the forum.

    Can someone help please? My best solution so far is to sort by year, and then sort descending those records that do not include total and then use vlookup again. I need it to immediately reflect any changes to the file.

    I am using Excel 16 on Windows 10. Sample file attached.

    Thankyou in advance.
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Use vlookup to return first and last-but-one values

    Hi fred and welcome to the forum,

    You first need to make those year cells real numbers. You should also get rid of the "Total" using an IFError(). Then do a Pivot Table showing the Min and Max and problem solved. See the attached.

    PT showing first and last years.xlsx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,935

    Re: Use vlookup to return first and last-but-one values

    I must say PT is one of the easiest solution so far for these type of data. However if your wish formula solution please see below.

    Excel 2016 (Windows) 64 bit
    A
    B
    C
    D
    E
    F
    G
    1
    Name Year Name first year last year
    2
    NameA 1960 NameA
    1960
    1961
    3
    NameA 1961 NameB
    2004
    2006
    4
    NameA Total NameC
    1957
    1964
    5
    NameB 2004 NameD
    2018
    2018
    6
    NameB 2005
    7
    NameB 2006
    8
    NameB Total
    9
    NameC 1957
    10
    NameC 1960
    11
    NameC 1964
    12
    NameC Total
    13
    NameD 2018
    14
    NameD Total
    Sheet: Sheet1

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


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


    Drag down!
    If I helped, Don't forget to add reputation (click on the little star ★ at bottom of this post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  4. #4
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: Use vlookup to return first and last-but-one values

    at G2 array formula (CSE)

    =MAX(IFERROR(IF($A$2:$A$14=E2,--$B$2:$B$14),))

    copy down

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Use vlookup to return first and last-but-one values

    If your years were real numbers, you could use:

    =MINIFS(B2:B14,A2:A14,E2)

    =MAXIFS(B2:B14,A2:A14,E2)
    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.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. Vlookup return multiple values horizontally for a list of values
    By lucipurr in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-07-2018, 11:00 AM
  2. Getting Sum of values from VLOOKUP return
    By alonkey in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-05-2016, 01:07 PM
  3. vlookup but return all values
    By ammartino44 in forum Excel General
    Replies: 2
    Last Post: 07-27-2015, 05:02 PM
  4. Replies: 13
    Last Post: 10-13-2014, 02:00 AM
  5. Vlookup to return all values not just the first!
    By hkhan11 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-11-2013, 05:57 AM
  6. vlookup multiple values and return values
    By AMFISH in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2012, 11:13 AM
  7. Return 2 values from vlookup
    By adsxvii in forum Excel General
    Replies: 4
    Last Post: 08-28-2008, 09:27 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