A lookup using INDEX and MATCH is like a VLOOKUP without the restrictions. Index and Match lookups offer you freedom, to search to the left as well as the right and to perform more complex two way lookups with ease.
Performing an Index/Match lookup is confusing at first. Here, I'll show you how to do everything step by step.
(before you start, make sure to download the sample file for this tutorial so you can follow along with the examples below)
Create a Lookup Using INDEX and MATCH
Create a Right-to-Left Lookup Using INDEX and MATCH
Create a Two-Way Lookup Using INDEX and MATCH
This is how to create a basic lookup. This will be the simplest version of a lookup and it will work exactly like a Vlookup; it's important to start simple so you can get a feel for how we input the formula.
In the example below, we want to search a "Rank" column and have it return a value from the "Site" column.
Now, if you don't already have a value in cell A2, the lookup will return a #N/A error.
Type a search value into cell A2 and we get this:
The final formula that we entered is this:
=INDEX(E5:E9,MATCH(A2,D5:D9,0))
E5:E9 is the range from which you want to return values, where you want the lookup function to get the values that it displays to you.
D5:D9 is the range that you use to search through the table, using the lookup_value.
A2 is the cell that contains the lookup_value that you use to search through the table/column/range.
To make this work, the two ranges that you use must be exactly the same size. It's best if they come from the same data set or table.
This is the real beauty of this type of lookup. We can return a value from ANYWHERE in the table!!! With a Vlookup, we can only return a value that is to the right of the lookup column.
If you read the first example above, this one is very similar.
In the example below, we want to search the "Site" column and return a value from the "Rank" column.
Now, if you don't already have a value in cell B2, the lookup_value cell, the lookup will return a #N/A error.
Input a search value into cell B2, in this case a site name, and we get a result like this:
What happened here is that we performed a lookup that searched through the Site column for blue.com and returned a number from the Rank column, 3, which is located to the left of the Site column.
Now you know how to perform a right-to-left lookup in Excel!
Here is the final formula that we created:
=INDEX(D5:D9,MATCH(B2,E5:E9,0))
D5:D9 is the range from which you want to return values, where you want the lookup function to get the values that it displays to you.
E5:E9 is the range that you use to search through the table, using the lookup_value.
B2 is the cell that contains the lookup_value that you use to search through the table/column/range.
As you can see, it does not matter if the column that returns the values is to the left or right of the lookup range. The only IMPORTANT thing is that the columns have to be the same size, and it helps if they are also in the same table. As a rule of thumb, make sure both columns you input into this formula are from the same data set/table; this will make things much easier for you.
This allows you to search up and down and also left and right at the same time using a single formula.
This is a confusing formula to use at first, so I will go step-by-step to tell you how to input it and then make it work for your code. This follows the same principal as the above examples; however, we need to add an additional set of steps.
In this example I will use two values to perform the lookup, one to search for a specific Site and one to return data for a specific year for that Site.
Now, at first, you will see an error message like this: #N/A and that is just because there is no value for Year or Site yet.
Once we fill out the values for Year and Site, it looks like this:
You can see that the search was performed to find red.com and then to find the data for year 2014.
Here is the final formula that was used:
=INDEX(C5:F10,MATCH(B2,C5:C10,0),MATCH(B1,C5:F5,0))
Follow the instructions above carefully the first few times you make this formula so you can get a feel for it. Once you do that, there are only a few things that you need to change to make it work with any data set.
To get this to work for you, change 5 things:
C5:F10 is the table that contains the data set.
B2 is the cell that will contain the value you will use to search through the rows to find the correct row.
C5:C10 is the range that you use the value in cell B2 to search through in order to find a match to know from which row to return data.
B1 is the cell that contains the value that you use to determine from which column to return data.
C5:F5 is the range that you use the value in cell B1 to search through in order to find a match and know from which column to return data.
The INDEX MATCH lookup function is very powerful and allows you to do things that you simply can't do with a Vlookup or Hlookup function. The problem is that it is quite complex and confusing. But, trust me, once you get started using this method and become comfortable using it in different ways, you will consider this a miracle function that saves you hours of time and many headaches.
Make sure to download the sample file attached to this tutorial so that you can follow along and get a better grasp of how to use this formula.