How To Use INDEX and MATCH - Exceljet PDF
How To Use INDEX and MATCH - Exceljet PDF
Search... Search
Introduction
Apart from VLOOKUP, INDEX and MATCH is the most widely used tool in Excel for
performing lookups. The INDEX and MATCH combo is potent and exible, and you'll see
it used in all kinds of formulas, from basic to very advanced.
However, while VLOOKUP allows you to perform lookups with a single function, INDEX
and MATCH requires two functions, one nested inside another. Many users nd this
confusing, because they aren't used to combining functions in Excel, so they avoid INDEX
and MATCH. That's a shame. Combining functions is the key to more advanced formulas in
Excel.
This article explains in simple terms how to use INDEX and MATCH together to perform
lookups. It takes a step-by-step approach, rst explaining INDEX, then MATCH, then
showing you how to combine the two functions together to create a dynamic two-way
lookup.
The INDEX function in Excel is fantastically exible and powerful, and you'll nd it in a
huge number of Excel formulas, especially advanced formulas. But what does INDEX
actually do? In a nutshell, INDEX retrieves values at a given location in a list or table. For
example, let's say you have a table of planets in our solar system (see below), and you
want to get the name of the 4th planet, Mars, with a formula.
You can do it with this simple formula based on the INDEX function:
= INDEX(B3:B11,4)
INDEX locates the 4th cell in B3:B11, B6, and returns the value at that address.
What if you want to get the diameter of Mars? In that case, we can give INDEX both a row
number and a column number, and feed in a larger array (range) of data. The INDEX
formula below uses the full range of data in B3:D11, with a row number of 4 and column
number of 2:
= INDEX(B3:D11,4,2)
How INDEX can be used to retrieve a value in a 2D table.
At this point, you may be thinking "So what? How often do you actually know the position
of something in a spreadsheet?"
Exactly right. We need a way to locate the position of things we're looking for.
The MATCH function is designed for one purpose: nd the numeric position of an item in
a list. For example, we can use MATCH to get the position of the word "peach" in this list
of fruits like this:
= MATCH("peach",B3:B9,0)
MATCH returns 3, since "Peach" is the third item in the range. Notice MATCH is not case-
sensitive.
MATCH doesn't care if the list is horizontal or vertical. If we arrange the list of fruits
horizontally, we get the same result with this MATCH formula:
= MATCH("peach",C4:I4,0)
The MATCH function with a horizontal range. Same result, MATCH returns 3.
For basic exact match lookups, you'll want to specify zero, to force an exact match.
However, if you need an approximate match to lookup values along a scale, you'll want to
use either 1 or -1, and you'll need to sort the lookup array according to your needs, [A-Z]
when match type is 1, [Z-A] when match type is -1.
Let's say we want to write a formula that returns the sales number for February for any
given salesperson. From the discussion above, we know we can give hardcoded values to
INDEX to retrieve a value. For example, to return the February sales number for Frantz,
this INDEX formula will do the job:
= INDEX(C3:E11,5,2)
Here we ask INDEX for the value in row 5, column 2 from the range C3:E11, and INDEX
returns $5,194.
But we obviously don't want to hardcode values. Instead, we want a dynamic lookup.
Working one step at a time, let's leave the column hardcoded as 2 and make the row
number dynamic. How will we do that? The MATCH function of course! MATCH will work
perfectly for nding the position of Frantz in the list of names. Here's a revised formula,
using the MATCH function, inside of INDEX. Notice we have replaced the number 5 with
MATCH:
= INDEX(C3:E11,MATCH("Frantz",B3:B11,0),2)
When MATCH nds "Frantz" in B3:B11, it returns the number 5 directly into INDEX:
= INDEX(C3:E11,5,2)
Naturally, we don't want to hardcode the name either. What we need is a way to input
*any* name, then let INDEX and MATCH do their magic.
The screen below shows a very simple implementation of this idea. The formula in H3 is:
= INDEX(C3:E11,MATCH(H2,B3:B11,0),2)
Above, we used the MATCH function to nd the row number for any given salesperson. To
keep things simple, we hardcoded the column number 2 to get sales for February. How can
we make the formula fully dynamic, so we can can return sales for any given salesperson
in any given month? The trick is to use MATCH twice – once to get a row position, and
once to get a column position.
From the examples above, we know MATCH works ne with both horizontal and vertical
arrays. That means we can easily nd the position of a given month with MATCH. For
example, this formula return the position of March, which is 3:
= MATCH("Mar",C2:E2,0)
But of course we don't want to hardcode any values, so let's update the worksheet to allow
the input of a month name, and use MATCH to nd the column number we need. The
screen below shows the result:
We know have a fully dynamic, two-way lookup with INDEX and MATCH, and the formula
looks like this:
= INDEX(C3:E11,MATCH(H2,B3:B11,0),MATCH(H3,C2:E2,0))
The rst MATCH formula returns 5 to INDEX as the row number, the second MATCH
formula returns 3 to INDEX as the column number. Once MATCH runs, the formula
simpli es to:
= INDEX(C3:E11,5,3)
and INDEX correctly returns $10,525, the sales number for Frantz in March.
Note: you could use Data Validation to create simple dropdown menus for both
salesperson and month.
Video: How to debug a formula with F9 (to see MATCH return values)
Here are some other examples of INDEX and MATCH in action, each with a detailed
explanation:
Spoiler rst: INDEX + MATCH can do everything VLOOKUP can do, and more. It's simply a
more exible way to look things up. Here are a few advantages over VLOOKUP:
INDEX and MATCH can look left or right in a table, VLOOKUP can only look right
INDEX and MATCH can work with horizontal or vertical ranges, VLOOKUP can
only use vertical ranges
INDEX and MATCH can work with data sorted in descending order, VLOOKUP can
only match data sorted in ascending order
If you have a large set of data, INDEX and MATCH can be faster
However, there is no reason not to use VLOOKUP when the situation ts. It's an excellent
function with it's own bene ts:
To learn more about VLOOKUP, see this article: 23 things you should know about
VLOOKUP.
Related courses
Core Formula
Topics
Video training
Function Guide
Formula Examples
Formula Criteria
Excel Shortcuts
Pivot Tables
101 Excel Functions
Excel Tables
INDEX and MATCH
Excel Charts
Conditional Formatting
Custom Number Formats
Data Validation
Nested IF examples
Formula challenges
How-to videos
Excel glossary
Excel people
Excel books
Recent comments
Key functions
IF function
VLOOKUP function
SUMIFS function
COUNTIFS function
INDEX function
MATCH function
SUMPRODUCT function
Learn more