Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to vlookup the last or first matching value in Excel?

If you have a list of items which are repeated many times, and now, you just want to know the last matching value with your specified data. For example, I have the following data range, there are duplicate product names in column A but different order numbers in column B, and I want to return the last matching value 174 of the product KTE as following screenshot shown:

doc-lookup-last-match-1

Vlookup the last matching value in Excel with formulas

Vlookup the first matching value in Excel with Kutools for Excel


arrow blue right bubble Vlookup the first matching value in Excel with Kutools for Excel

Kutools for Excel collects multiple commonly used formulas, with them, you can quickly calculate age from a birthday, add years, months, weeks or days to a given date, vlookup and return the matching value from a table, and so on.

doc-lookup-last-match-1

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


arrow blue right bubble Vlookup the last matching value in Excel with formulas


To vlookup and return the certain value you need, the vlookup function will be first in your mind, but, with the vlookup function you just return the first matching value not the last. Here, I will talk about some other formulas to deal with this task.

Please enter this formula =LOOKUP(2,1/(A2:A12=D2),B2:B12) into your specified cell and press Enter key to get the last corresponding value as follows:

doc-lookup-last-match-1

Notes:

1. If there is no data in the last matching cell, you will get a result of 0, but that is not your need, you want the last non-zero value, in this case, you should use the following array formula: =LOOKUP(9.99999999999999E+307,IF(A2:A12=D2,IF(ISNUMBER(B2:B12),B2:B12))) and press Ctrl + Shift + Enter keys together.

doc-lookup-last-match-1

2. In the above formulas, A2:A12 indicates the column that you are looking for, D2 is the value which you want to return its relative information and B2:B12 is the list that contains the value you want to return.

3. The value you are looking for is not case sensitive.


Related articles:

How to use vlookup exact and approximate match in Excel?

How to vlookup values from right to left in Excel?

How to lookup value to match case sensitive in Excel?


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Alaa · 11 months ago
    Thank you for the formula its genius
    I used your formula to come up with a fix for the blank cells without using CSE (Ctrl + Shift + Enter)
    =LOOKUP(3,(1/(A2:A12=D2))+(1/(B2:B12<>"")),B2:B12)
  • To post as a guest, your comment is unpublished.
    Mayank Channa · 1 years ago
    In the above formula "=LOOKUP(9.99999999999999E+307,IF(A2:A12=D2,IF(ISNUMBER(B2:B12),B2:B12)))" why that "9.99999999999999E+307" has been taken in this?
  • To post as a guest, your comment is unpublished.
    Megan · 1 years ago
    Is there any way to combine this with TEXT values, which are in another sheet?
  • To post as a guest, your comment is unpublished.
    Mike Jones · 2 years ago
    Thanks, this is brilliant
  • To post as a guest, your comment is unpublished.
    Magil · 2 years ago
    Oh. My God. How that. Impressed.. :)
  • To post as a guest, your comment is unpublished.
    Bes · 2 years ago
    I would also like to know why "2" and what "1/(A2:A9=D2)" is ?
    • To post as a guest, your comment is unpublished.
      Ali AlKhawaher · 2 years ago
      Actually, I tried to understand and this is what I understand,

      1. (A2:A9=D2) will return an array of true/false values depending on D2 value
      2. The author divide one by the array of true/false to convert them to numbers
      3. Then he lookup for 2 in the array which will return the last value. After I understood this, i was able to simplify the formula to the following which will give the same results with no conversions tricks

      =LOOKUP(TRUE,(A2:A12=D2),B2:B12)
  • To post as a guest, your comment is unpublished.
    SandyC · 2 years ago
    Really impressed with this. However I don't understand what the 2 represents. Seems it's relevant to an array/vector formula. Online help no use of course. :-)
  • To post as a guest, your comment is unpublished.
    Biswajit Malakar · 2 years ago
    Why we have written 1/(A2:A9=D2), can someone please explain?
  • To post as a guest, your comment is unpublished.
    Glenn · 2 years ago
    This was really helpful! Thank you!