Interactive INDEX Example

Excel Index and Match Functions

Use the INDEX and MATCH functions to pull data from a list. These functions can be used together, to create a powerful and flexible formul

INDEX and MATCH Introduction

  • The INDEX function can return an item from a specific position in a list.
  • The MATCH function can return the position of a value in a list.
  • The INDEX / MATCH functions can be used together, as a flexible and powerful tool for extracting data from a table.

Video: INDEX Function

In this video, you'll see how to use the INDEX function to:
  • Find sales amount for selected month
  • Get reference to specified row, column, area
  • Create a dynamic range based on count
  • Sort column of text in alphabetical order
There are other INDEX examples below the video. For written instructions for this video, see the Contextures Blog article: 30 Excel Functions in 30 Days: 24 - INDEX

INDEX Function -- Arguments

The INDEX function has three arguments:
Excel INDEX MATCH 01
  1. array: Where is the list? If you use an absolute reference ($A$2:$B$4), instead of a relative reference (A2:B4), it will be easier to copy to formula to other cells. Or, name the lookup table, and refer to it by name.
  2. row_num: Which row has the value you want returned? In this example, the item in the third row will be returned.
  3. [column_num]: Which column has the value you want returned? In this example, the item in the second column will be returned.go to top
Excel INDEX MATCH 01

INDEX Function -- Example

The INDEX function can return an item from a specific position in a specific column in a list. For example, what is the 3rd item in the 2nd column in the list below?
Excel INDEX MATCH 01
  1. Select the cell in which you want the result
  2. Type an equal sign, the INDEX function name, and an opening parenthesis:
          =INDEX(
  3. Select the cells that contain the list -- cells A2:B4 in this example
  4. Press the F4 key on the keyboard, to change the reference to an absolute reference: $A$2:$B$4. Then, if you copy the formula to another cell, it will continue to refer to the list of items.
  5. Type a comma, to separate the arguments
  6. Type the number of the item you want to return -- 3 in this example
  7. Type a comma, to separate the arguments
  8. Type the number of the column you want to return -- 2 in this example
  9. Finish with a closing parenthesis. The completed formula is:
          =INDEX($A$2:$B$4,3,2)
  10. Press the Enter key to see the result. 

In the embedded Excel file shown below, you can see the INDEX function example. On Sheet 1, the row and column numbers are typed in the formula -- hard-coded.

NOTE: The interactive file might not be viewable on all devices or browsers.
On Sheet 2, the row and column numbers are in worksheet cells. Change the row or column number to change the formula result.

MATCH Function -- Arguments

The MATCH function has three arguments:
match function arguments
To view the steps in a short video, click here
  1. lookup_value: What value do you want to find in the list? You can type the value, or refer to a cell that contains the value.
  2. lookup_array: Where is the list?
  3. [match_type]: Match_type can be -1, 0, or 1. It tells Excel how to match the lookup_value to values in the lookup_array. 
     1 -- find the largest value less than or equal to lookup_value 
             (the list must be in ascending order) 
     0 -- find the first value exactly equal to lookup_value. Lookup_array
             (the list can be in any order)
    -1 -- find the smallest value greater than or equal to lookup_value. 
             (the list must be in descending order)
    Note: If match_type is omitted, it is assumed to be 1.go to top

MATCH Function -- Example

The MATCH function can find a value in a list, and return its position. For example, where is "Jacket" in the list below?
Excel INDEX MATCH 01
  1. Select the cell in which you want the result
  2. Type an equal sign, the MATCH function name, and an opening parenthesis:
          =MATCH(
  3. Type the value to find, or click on the cell that contains the value -- cell A5 in this example
  4. Type a comma, to separate the arguments
  5. Select the range that contains the list -- a range named ItemList in this example
  6. Type a comma, to separate the arguments
  7. Type the number for the Match type you want to use -- 0 was used in this example, because an exact match is required.
  8. Finish with a closing parenthesis. The completed formula is:
          =MATCH(A5,ItemList,0)
  9. Press the Enter key to see the result.go to top

INDEX / MATCH -- Example 1

One advantage of the INDEX / MATCH functions is that the lookup value can be in any column in the array, unlike the VLOOKUP function, in which the lookup value must be in the first column.
In this INDEX / MATCH example, the MATCH function will find the position of "Jacket" in column B, and the INDEX function will return the code from the same position in column A.
Excel INDEX MATCH 01
  1. Set up the worksheet as shown at right
  2. Enter the following formula in cell B6:
          =INDEX($A$2:$A$4,MATCH(A6,$B$2:$B$4,0))
  3. Press the Enter key to see the result.
The MATCH function, MATCH(A6,$B$2:$B$4,0), returns 2, which is the position of "Jacket" in the list.
Then, the INDEX function, INDEX($A$2:$A$4,2), returns "JK002", which is the second item in the range $A$2:$A$4go to top

INDEX / MATCH -- Example 2

The MATCH function can be used to return values for both the row_num and column_num arguments in the INDEX function.
Excel INDEX MATCH 01
  1. Set up the worksheet as shown above
  2. Enter the following formula in cell C7:       =INDEX($B$2:$D$4,MATCH(B7,$A$2:$A$4,0),MATCH(A7,$B$1:$D$1,0))
  3. Press the Enter key to see the result.
The first MATCH function, MATCH(B7,$A$2:$A$4,0), returns 3, which is the position of "Pants" in the Items list.
The second MATCH function, MATCH(A7,$B$1:$D$1,0), returns 2, which is the position of "Med" in the Size list.
Then, the INDEX function, INDEX($B$2:$D$4,3,2), returns "30", which is the third item in the second column in the range $B$2:$D$4go to top

INDEX / MATCH -- Example 3

To make the previous example even more flexible, you can use the INDEX function within the MATCH function, to look for values in the first row or column of a named table. (This INDEX / MATCH example is from a newsgroup posting by Peo Sjoblom)
Excel INDEX MATCH 01
Set up the worksheet as shown above
  1. The green cells are a range named Table). (Instructions on naming a range)
  2. Enter the following formula in cell C7:       
    =INDEX(Table,MATCH(B7,INDEX(Table,,1),0),MATCH(A7,INDEX(Table,1,),0))
  3. Press the Enter key to see the result.
The first MATCH function, MATCH(B7,INDEX(Table,,1),0), looks for "Pants" in the first column of the Table range (A1:A4), and returns 4.
The second MATCH function, MATCH(A7,INDEX(Table,1,),0), looks for "Med" in the first row of the Table range (A1:D1), and returns 3.
Then, the INDEX function, INDEX(Table,4,3), returns "30", which is in the fourth row in the third column in the range named Tablego to top  

Lookup 2 Criteria -- Example 4

For some Excel lookups, you may need to match 2 or more criteria. This video shows how to use 2 criteria - Item name and product Size, to get the correct price.
Watch the video, to see the steps, and the written instructions are on the Lookup - 2 Criteria page. If you download the sample file on this page, this is on the Example 4 worksheet.
Excel INDEX MATCH 01

Video: Lookup With Multiple Criteria

For details on how this formula works, to to the Lookup - 2 Criteria page.
go to top

Video: Find Best Price With INDEX, MATCH, MIN

This video shows how to combine INDEX, MATCH and MIN, to show the name of the store that has the lowest price. MIN calculates the lowest price, and MATCH locates that price in the row. INDEX returns the store name for the selected column.
To follow along with this video, download the Best Price workbook. It is in xlsx format, and zipped. There are no macros in the file.
For written instructions, go to Find Best Price with Excel INDEX and MATCH on my blog.

Video: Find Distance Between Cities with INDEX / MATCH

From a lookup table with distances between cities, you can use the INDEX and MATCH functions to show the mileage between two selected cities.
Watch this video to see the steps, and you can download the video's sample file to see how it works.

Troubleshoot the MATCH formula

Your MATCH formula may return an #N/A, even though the value you're looking for appears to be in the lookup array.

Text vs. Number

A common cause for this error is that one of the values is a number, and the other is text. For example, the lookup array may contain '123 (text), and the value to look up is 123 (a number). Or, if you have downloaded data from a database, it may contain text codes with leading zeros, e.g. 00123, and your Excel file may contain numbers formatted with leading zeros.
If possible, convert the text to numbers, using one of the methods shown here:
      Convert Text to Numbers
If you can't convert the data, you can convert the lookup value within the MATCH formula:

Lookup values are Text, and the table contains Numbers

If the lookup array contains numbers, and the value to look up is text, use a formula similar to the following:
=MATCH(--A5,ItemList,0)
The double unary (--) converts text to a number, and will work correctly even if the lookup values are numbers.

Lookup values are Numbers, and the table contains Text

If the lookup array contains text, and the value to look up is numeric, use a formula similar to the following:
=MATCH(A5 & ""),ItemList,0)
OR
=MATCH(TEXT(A5,"00000"),ItemList,0)
The TEXT function converts a number to text, and will work correctly even if the lookup values are text. In the first example, the & operator creates a text string from an unformatted number. In the second example, a number formatted with leading zeros (e.g. 00123) would match a text "number" with leading zeros.

Spaces in one value, and not the other

Another potential cause for no matching value being found is a difference in spaces. One of the values may contain leading spaces (or trailing, or embedded spaces), and the other doesn't. To test the values, you can use the LEN function, to check the length of each value. 
For example:   =LEN(A5)     will return the number of characters in cell A5. It should be equal to the number of characters in the matching cell in the lookup table.
If possible, remove the unnecessary spaces, and the MATCH formula should work correctly. If you can't remove the spaces, use the TRIM function in the MATCH, to remove leading, trailing or duplicate spaces. For example:
    =MATCH(TRIM(A5),ItemList,0)

HTML characters in one value, and not the other

If you copied data from a web page, it may contain non-breaking space (&nbsp) characters. David McRitchie has written a macro to remove them, along with other spaces characters -- https://www.mvps.org/dmcritchie/excel/join.htm#trimall   go to top  

Download the Sample File