Yesterday, in the 30XL30D challenge, we found text strings with the FIND function, and learned that it is case sensitive, unlike the SEARCH function.
NOTE: You can have all of the 30 Functions content in an easy-to-use single reference file -- the 30 Excel Functions in 30 Days eBook Kit ($10).
For day 24 in the challenge, we'll examine the INDEX function. Based on a row and column number, it can return a value or reference to a value. We've already used INDEX several times, with other functions in the challenge:
- with EXACT to find name for the password with exact match
- with AREAS to find the last area in a named range
- with COLUMNS to calculate sum of last column in range
- with MATCH to find the name for closest guess in a contest
So, let's take a look at the INDEX information and examples, and if you have other tips or examples, please share them in the comments.
Function 24: INDEX
The INDEX function returns a value or reference to a value. Combine it with other functions, like MATCH, for powerful formulas.
How Could You Use INDEX?
The INDEX function can return a value or reference to a value, so you can use it 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
The INDEX function has two syntax forms -- Array and Reference. With Array form, a value is returned, and with Reference form, a reference is returned.
The Array form has the following syntax:
- array is an array constant or range of cells
- if array has only 1 row or column, corresponding row/column number argument is optional
- if array has >1 row or column, and only row_num or column_num is used, array of entire row or column is returned
- row_num – if omitted, column_num is required
- column_num – if omitted, row_num is required
- if both the row_num and column_num arguments are used, returns value in cell at intersection of row_num and column_num
- if row_num or column_num are zero, returns array of values for entire column or row
The Reference form has the following syntax:
- reference can refer to one or more cell ranges – enclose nonadjacent ranges in parantheses
- if each area in reference has only 1 row or column, corresponding row/column number argument is optional
- area_num selects range in reference from which to return row and column intersection
- area_num – if omitted, area 1 is used
- if row_num or column_num are zero, returns reference for entire column or row
- result is a reference, and can be used by other functions
If the row_num and column_num don't point to a cell within the array or reference, the INDEX function returns a #REF! error.
Example 1: Find sales amount for selected month
Enter a row number, and the INDEX function returns the sales amount from that row in the reference. Here the month number is 4, so the April sales amount is returned.
To make the formula more flexible, you could use MATCH to return the row number, based on the month that was selected from a drop down list.
Example 2: Get reference to specified row, column, area
In this example, there is a named range, MonthAmts, which consists of 3 non-contiguous ranges. The MonthAmts range has 3 areas -- one for each month -- and there are 4 rows and 2 columns in each area. Here is the formula for the MonthAmts name:
With the INDEX function, you can return the cost or revenue amount for a specific region and month.
The INDEX function result can be multiplied, as in the Tax calculation in cell F10:
or, it can return a reference for the CELL function, to show the address of the result, in cell G10.
Example 3: Create a dynamic range based on count
You can also use the INDEX function to create a dynamic range. In this example, I've created a name, MonthList, with this formula:
If another month is added to the list in column C, it will automatically appear in the data validation drop down list in cell F2, which uses MonthList as its source.
Example 4: Sort column of text in alphabetical order
In the final example, the INDEX function is combined with several other functions, to return a list of months, sorted in alphabetical order. The COUNTIF function shows how many month names come before a specific month name. SMALL returns the nth smallest item in the list, and MATCH returns the row number for that month.
In the video, you can see the formula broken down into steps.
This formula is array-entered, by pressing Ctrl + Shift + Enter.
Download the INDEX Function File
To see the formulas used in today's examples, you can download the INDEX function sample workbook. The file is zipped, and is in Excel 2007 file format.
Watch the INDEX Video
To see a demonstration of the examples in the INDEX function sample workbook, watch this short Excel video tutorial.