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

Build Hyperlink With VLOOKUP in Excel

You might have come across a task in which you were assigned to build hyperlinks, which seems very easy, and if you are new to excel or don't have enough experience with it, then you might wonder about doing this ...

Calculate Total Cost with Excel VLOOKUP Function

In today's article we will show you how to calculate the total cost for a given weight using the Excel VLOOKUP function. This function will help us to find the appropriate unit price for that weight and then we can ...

Basic Price Discount Calculation with Excel VLOOKUP Function

We often encounter product discounts in our shopping. Depending on the level of spending, the mall will offer different percentages of discounts. Usually, the more you spend, the bigger the discount, while the less you spend, the smaller the discount. ...

Calculate Grades With VLookup in Excel

Why Should You Calculate Grades With VLookup Excel? If you're looking for a simple way to find out a student's grades, VLOOKUP Excel can do the trick. This function uses a lookup table to find the values and sort them ...

Convert State Names To Abbreviations
abbr state names1

Assume that you got a task to convert the full state's name into the abbreviations in MS Excel, and for doing this task, you might choose to do it manually, which is an acceptable way only if you don't have ...

Find and Replace Multiple Values
find replace multiple values5

This post will guide you how to find and replace multiple values at once with VBA macro or using formula  in Excel. How do I make multiple find and replace in Excel. Suppose that you have a few cells containing ...

Excel XLOOKUP Function

Excel XLOOKUP Function was added into Excel as a beta feature in August 2019 and is now accessible exclusively in Microsoft 365. (as of July 2021). However, if you fall into this category and often deal with big sets of ...

VLOOKUP Formula | Faster Trick with 2 VLOOKUPS

This post will guide you how to use 2 VLOOKUPS function to looking up data entries from a given range of cells in Microsoft Excel. VLOOKUP with 2 lookups can be faster than a single VLOOKUP in certain scenarios. The ...

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 ...

Sidebar