Vlookup to Find Last Matching Value

Lookup Function to Get Last Matching Value in Microsoft Excel

If you are wondering what formula should be used in order to get the last matching value in Excel to return the corresponding cell value, then this article is for you.

In this article, we will learn to use lookup function to get last matching value out of multiple values.

Question): I need a formula to look up the conditional value in a specific column & find the last occurred item & then return the corresponding value.

The data we will consider in this example has some names in column A, couple of them are repeated to have better understanding of this example; the second column has sale quantity.

Following is the snapshot of the sample data:

  • The formula should first of all check should check the number of times the criteria text found & then provide the adjacent value.

 

img1

 

  • In cell E2, the formula is
  • =LOOKUP(2,1/($A$2:$A$8=D2),$B$2:$B$8)

 

img2

 

Code Explanation:

  • This part ($A$2:$A$8=D2) evaluates to an array of TRUEs/FALSEs.
  • 1 should be divided each of these evaluates to an array of 1′s and #DIV/0! error (because 1/True is like 1/1, which equals 1 and 1/False is like 1/0 which results in an error.
  • The Lookup() function looks for the last entry that is less than or equal to the Lookup value… so looking for a 2 in an array of 1′s and #DIV/0!’s will result in returning the last 1 in the array
  • This is then matched to the Result Vector; B2:B8 to pull the coinciding value.

 

To test the above formula, we can either change the conditional text or change in source data.

 

img3

 

img4

 

In this way, find the quantity sale by last occurrence of the searched name.

image 4

Download – Lookup function to get last matching value – xlsx

Users are saying about us...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.

Visit Us On TwitterVisit Us On FacebookVisit Us On Google PlusVisit Us On Youtube