How to Use VLOOKUP to Find the First or Last Matching Value in Excel

VLOOKUP function is extremely strong among excel all functions and it is very useful in our daily work. It can save a lot of time if we want to find matching value from a long list and return the value we want. Normally we can find exact or approximate matching value from a list by setting False of True (the last argument) in formula =VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup]). If there is only one matching value, we can find it out easily no matter we set False or Ture to get exact or approximate matching value. But if there are more than one matching value, which matching value will be found? The first one or the last one? Actually, if we set False to get exact matching value, the first matching value will be found. On the other side, if we set True, the last matching value will be found instead. This article will show you some examples, now let’s see them.

Precondition:

Prepare two tables. In table1 we list different amounts for apple and banana on different dates. In table2 we list the amount for apple and banana on the first date and the last date. Obviously, we can use VLOOKUP function here to find matching value in Fruit column and then return amount value in Amount column. For “Amount of the First Date”, we can use VLOOKUP function to find the first matching value, for “Amount of the Last Date”, we can find the last matching value. Now let’s see steps below for finding first and last matching value.

Table 1:

Use VLOOKUP to Find The First or Last 1

Table 2:

Use VLOOKUP to Find The First or Last 2

Part 1: Use VLOOKUP to Find the First Matching Value


Step 1: In F2, enter the formula =VLOOKUP(E2,$A$2:$C$7,3,FALSE). Notice that we set range_lookup to False to get exact matching value here.

Use VLOOKUP to Find The First or Last 3

Step 2: Click Enter to get returned value. Verify that the first matching value is found in this case.

Use VLOOKUP to Find The First or Last 4

Step 3: Drag cell F2 down with formula to fill cell F3.

Use VLOOKUP to Find The First or Last 5

Now we can make sure that if there are more than one matching value exist in the list, we can set range_lookup to False to find the first matching value.

Part 2: Use VLOOKUP to Find the Last Matching Value


Step 1: In G2, enter the formula =VLOOKUP(E2,$A$2:$C$7,3,TRUE). Notice that we set range_lookup to True to get approximate matching value here.

Use VLOOKUP to Find The First or Last 6

Step 2: Click Enter to get returned value. Verify that the last matching value is found in this case.

Use VLOOKUP to Find The First or Last 7

Step 3: Drag cell G2 down with formula to fill cell G3. Verify that we get the last matching value properly.

Use VLOOKUP to Find The First or Last 8

Comment:

In above example, the matching values are sorted properly. If they are not sorted, we may get improper value with above formula. See table below.

Use VLOOKUP to Find The First or Last 9

In G2, we still enter the formula =VLOOKUP(E2,$A$2:$C$7,3,TRUE).After clicking Enter, we get 200, which is the amount for the second Apple in list.

Use VLOOKUP to Find The First or Last 10

So please be aware that if we want to get last matching value by setting True in formula, we must make sure the matching values are sorted properly.

Related Functions


  • Excel VLOOKUP function
    The Excel VLOOKUP function lookup a value in the first column of the table and return the value in the same row based on index_num position.The syntax of the VLOOKUP function is as below:= VLOOKUP (lookup_value, table_array, column_index_num,[range_lookup])….

 

Related Posts
VBA Macro For VLOOKUP From Another Sheet
vba macro for vlookup from another sheet1

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

VLOOKUP From Another Sheet Not Working
vlookup from another sheet not working3

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you reasons why your VLOOKUP formula is not working ...

Fix #N/A Error For VLOOKUP From Another Sheet
vlookup from anther sheet not working1

This post will show you how to fix the #N/A error why it occurs when you extract values from another sheet using VLOOKUP function in Excel 2016,2013,2010 or other Excel versions. How can you correct a #N/A error in VLOOKUP ...

Get Employee Information by VLOOKUP

VLOOKUP is one of the key functions among all lookup & reference functions in Excel. Today, in this article, we will show you the way to apply VLOOKUP to retrieve employee information. I hope this article will help you in ...

VLOOKUP with Two Lookup Tables

VLOOKUP is one of the key functions among all lookup & reference functions in Excel. Today we will show you the application of VLOOKUP function when there are two lookup tables. EXAMPLE Table1 and table2 record the rates of Y2020 ...

VLOOKUP with Multiple Lookup Values

VLOOKUP is one of the key functions among all lookup & reference functions in Excel. It can scan and retrieve data from a static or dynamic table based on your lookup value. It can perform approximate match or exact match ...

VLOOKUP Data by Date

VLOOKUP is one of the key functions among all lookup & reference functions in Excel. It can scan and retrieve data from a static or dynamic table based on your lookup value. It can perform approximate match or exact match ...

VLOOKUP – Retrieve Data from Another Workbook
VLOOKUP - Retrieve Data from Another Workbook 1

VLOOKUP is one of the key functions among all lookup & reference functions in Excel. It can scan and retrieve data from a static or dynamic table based on your lookup value. It can perform approximate match or exact match ...

VLOOKUP – Retrieve Data from Another Worksheet
VLOOKUP - Retrieve Data from Another Worksheet 3

VLOOKUP is one of the key functions among all lookup & reference functions in Excel. It can scan and retrieve data from a static or dynamic table based on your lookup value. It can perform approximate match or exact match ...

Case Sensitive Lookup with SUMPRODUCT and EXACT

Today, we will show you how to use SUMPRODUCT and EXACT to perform a case sensitive exact match. In this article, we provide a simple example to calculate bonus for employees whose names are case-sensitive. If you meet similar scenarios ...

Sidebar