Search Contextures Sites

INDEX MATCH - Excel Index Function and Excel Match Function

Excel INDEX Function -- Arguments 
Excel INDEX Function -- Example  
Excel MATCH Function -- Arguments 
Excel MATCH Function -- Example 
INDEX / MATCH Function -- Example 
INDEX / MATCH Function -- Example 2 
INDEX / MATCH Function -- Example 3 
INDEX / MATCH Function -- Example 4 
Troubleshoot the Excel MATCH function  

The Excel INDEX function can return an item from a specific position in a list.
The Excel 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.

Download the sample INDEX / MATCH workbook

 

 


Excel INDEX Function -- Arguments

The Excel 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.
 
A
B
C
D
E
1
  
Small
Med
Large  
2
Sweater
10
12
15
 
3
Jacket
30
35
40
 
4
Pants
25
30
35
 
5
         
6 Size Item Price    
7 Med Pants
?
   

 

Excel INDEX Function -- Example

The Excel 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 at right?

  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. 

 

 
A
B
1
Item
Price
2
Sweater
10
3
Jacket
30
4
Pants
25
5
=INDEX($A$2:$B$4,3,2)

Download the sample
INDEX/MATCH workbook

Excel MATCH Function -- Arguments

The Excel MATCH function has three 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.
 

Excel MATCH Function -- Example

The Excel MATCH function can find a value in a list, and return its position. For example, where is "Jacket" in the list at right?

  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.

 

 
A
B
 
1
Item
 
 
2
Sweater
 
 
3
Jacket
 
 
4
Pants
 
 
5
Jacket
=MATCH(A5,ItemList,0)

Download the sample
INDEX/MATCH workbook

INDEX / MATCH -- Example

One advantage of the Excel 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 Excel MATCH function will find the position of "Jacket" in column B, and the Excel INDEX function will return the code from the same position in column A.

  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$4

 

 

 
A
B
1
Code
Item
2
SW001
Sweater
3
JK002
Jacket
4
PN001
Pants
5
 
 
6
Jacket
JK002

INDEX / MATCH -- Example 2

The Excel MATCH function can be used to return values for both the row_num and column_num arguments in the Excel INDEX function.

  1. Set up the worksheet as shown at right
  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$4

 

 
 
A
B
C
D
1
 
Small
Med
Large
2
Sweater
10
12
15
3
Jacket
30
35
40
4
Pants
25
30
35
5
 
 
 
 
6
Size Item Price  
7
Med Pants
?
 

 

INDEX / MATCH -- Example 3

To make the previous example even more flexible, you can use the Excel 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)

  1. Set up the worksheet as shown at right
  2. The green cells are a range named Table). (Instructions on naming a range)
  3. Enter the following formula in cell C7:      
    =INDEX(Table,MATCH(B7,INDEX(Table,,1),0),MATCH(A7,INDEX(Table,1,),0))
  4. 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 Table

 

  
 
A
B
C
D
1
Small
Med
Large
2
Sweater
10
12
15
3
Jacket
30
35
40
4
Pants
25
30
35
5
 
 
 
 
6 Size Item Price  
7 Med Pants
?
 

INDEX / MATCH -- Example 4

Instead of matching information in column headings, you may need to match information that's stored in the columns, as shown in the table at right.

In this INDEX / MATCH example, instead of columns headings of Small, Med, and Large, you need to find the price in column D, when Jacket is in column B, and Med is in column C.

  1. Set up the worksheet as shown at right
  2. Enter the following formula in cell C10:      
    =INDEX($D$2:$D$7,MATCH(1,(A10=$B$2:$B$7)*(B10=$C$2:$C$7),0))
  3. This is an array formula, so hold Ctrl + Shift, and press the Enter key to see the result.

Curly brackets will be automatically added to the formula (don't type them yourself!), so the final result will look like this:

{=INDEX($D$2:$D$7,MATCH(1,(A10=$B$2:$B$7)*(B10=$C$2:$C$7),0))}

Note: You can adjust the ranges to match the data on your worksheet, but you can't refer to an entire column.  

 

  
 
A
B
C
D
1
Code
Item
Size
Price
2
SW001
Sweater
Small
10
3
JK001
Jacket
Small
30
4
PN001
Pants
Small
25
5
SW001
Sweater
Med
12
6
JK001
Jacket
Med
35
7
PN001
Pants
Med
30
8
       
9
Item Size Price  
10
Jacket Med
?
 
Download the sample
INDEX/MATCH workbook

 

Troubleshoot the Excel 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 -- http://www.mvps.org/dmcritchie/excel/join.htm#trimall  

   Download the sample INDEX/MATCH workbook

 

Learn how to create Excel dashboards.

Excel Function Tutorials

Excel SUM Function  
Excel VLOOKUP Function  
Excel INDEX / MATCH Functions   
Excel COUNT Function  
Excel INDIRECT Function  

Excel Video Tutorials:

 

       Home     Excel Tips     Excel Files     The Excel Store     Blog     Contact

 

Privacy Policy

 

Contextures Inc., Copyright © 2009.
All rights reserved.

 

Last updated: January 28, 2010 1:11 AM