Sub topic 11
INDEX: returning the value at a position
This chapter assumes you can enter formulas, use absolute references such as $C$3:$C$12, and read a simple budget or assumptions sheet. It covers INDEX on its own. The next chapter pairs it with MATCH to build a lookup.
What INDEX does
INDEX returns the value in a range at a position you give it. It does not search for anything. You supply a range and a number, and it returns the item at that number.
=INDEX(array, row_num, [column_num])arrayis the block of cells to pick from.row_numis how many rows down from the top of that block.column_numis how many columns across from the left of that block. It is optional for a single row or column.
The position counts inside the range, not on the sheet. The first cell of the range is always position 1, wherever the range sits.
One-dimensional ranges
Suppose the Assumptions sheet holds keys in B3:B12 and values in C3:C12. The fourth value in the list is:
=INDEX(Assumptions!$C$3:$C$12, 4)That returns the contents of Assumptions!C6, because C3 is position 1, C4 is 2, C5 is 3 and C6 is 4. If you copy the range to a different place on the sheet, the position still means the same thing: the fourth cell down.
A single row works the same way. For a row range, the one number counts across:
=INDEX(Assumptions!$C$4:$E$4, 2)This returns Assumptions!D4. Excel treats the number as a column position because the range has only one row.
Two-dimensional ranges
For a block with several rows and columns, give both positions. The row comes first, then the column.
=INDEX(Rates!$C$3:$H$12, 2, 3)The block starts at C3. Row 2 of the block is sheet row 4, and column 3 of the block is column E. The formula returns Rates!E4.
If you pass only one number to a two-dimensional range, Excel treats it as the row number and returns the whole row. In current Excel that result spills across several cells. In a model this is usually not what you want, so always give both numbers for a block.
A model use: choosing a scenario by number
A common use in a financial model is a scenario switch. Assumptions row 4 holds the growth rate for three scenarios in C4:E4, in the order Base, Upside, Downside. A selector cell on the Summary sheet holds 1, 2 or 3.
=INDEX(Assumptions!$C$4:$E$4, Summary!$B$1)Change Summary!B1 from 1 to 3 and the formula returns the Downside rate. Every downstream formula points at this one cell, so the whole model changes with one input.
Put the selector on an input sheet and add data validation that allows only whole numbers from 1 to 3. Without that, a typed 4 produces an error that spreads through the model.
Zero returns a whole row or column
A position of 0 means "all of it". With a two-dimensional range, a row position of 0 returns the entire column you name, and a column position of 0 returns the entire row.
=SUM(INDEX(Rates!$C$3:$H$12, 0, 3))This sums the third column of the block, which is column E. Zero is useful when a number picks which column to total. Replace the 3 with a cell reference and the same formula can total any column.
INDEX returns a reference, not just a value
INDEX hands back a cell reference, so it can sit on either side of a range operator. This gives a flexible year-to-date total. With monthly figures in C5:C16 and a month number in $B$2:
=SUM(C5:INDEX(C5:C16, $B$2))If $B$2 is 3, INDEX returns C7, the formula becomes SUM(C5:C7), and it totals the first three months. This is more stable than OFFSET. OFFSET is volatile, meaning it recalculates on every change anywhere in the workbook, and INDEX is not.
What can go wrong
INDEX does exactly what the numbers say, and it does not check that they mean what you intended.
| Situation | Result | Why |
|---|---|---|
| Row or column position larger than the range | `#REF!` | The position falls outside the range |
| Position is negative | `#VALUE!` | Negative positions are not allowed |
| Position is text or blank text | `#VALUE!` | A number is required |
| Position points at an empty cell | 0 | Excel shows an empty cell as 0 in a formula result |
| Range changed but position did not | Wrong value, no error | The position now points at a different item |
The last row is the dangerous one. An error is visible, but a wrong number is not. Suppose someone inserts a new assumption above the fourth row of a list that your formula reads with INDEX(..., 4). The range grows, the formula keeps pointing at position 4, and it now returns a different item with no warning.
An empty source cell returning 0 can also hide a missing input. If a blank assumption must never be treated as zero, test it before using it:
=IF(INDEX(Assumptions!$C$3:$C$12, 4)="", NA(), INDEX(Assumptions!$C$3:$C$12, 4))This returns #N/A when the cell is blank, so the gap shows up instead of becoming a silent zero.
Anchoring and bounding the range
The rules from the references chapter apply fully here. The range inside INDEX should normally be absolute, with dollar signs, so it does not drift when you copy the formula down or across. The position is the part that changes.
Two habits help:
- Bound the range to the real data, such as
$C$3:$C$12, rather than a whole column. The position then counts from a known first cell, and a mistake is easier to spot. - Keep the range and its keys the same size. If the keys are in B3:B12, the values should be in C3:C12. A mismatch of even one row shifts every answer.
When INDEX alone is the right tool
INDEX alone fits when the position is genuinely a number you hold: a scenario number, a month number, or a loop counter in a schedule. It is the wrong tool when you have only a label such as an account name or a product code. Then something has to turn the label into a position, and that is the job of MATCH.
Exercise
The block Rates!$C$3:$H$12 has rows 3 to 12 and columns C to H. What cell does =INDEX(Rates!$C$3:$H$12, 4, 2) return, and why?
Show answer
It returns Rates!D6. Position 4 down from row 3 is sheet row 6 (rows 3, 4, 5, 6), and position 2 across from column C is column D. Positions count inside the range, starting at 1.
Exercise
A model uses =INDEX(Assumptions!$C$3:$C$12, 11) and shows #REF!. What is the cause, and what is a quieter failure that INDEX can produce when the list is edited?
Show answer
The range has only 10 rows (3 to 12), so position 11 is outside it and gives #REF!. The quieter failure happens when a row is inserted or reordered inside the list while the formula keeps a fixed position. The formula then returns a different item and shows no error.
Exercise
Monthly revenue is in C5:C16 and the cell $B$2 holds the number of months elapsed. Write a formula that totals revenue for the elapsed months.
Show answer
=SUM(C5:INDEX(C5:C16, $B$2)). INDEX returns a reference to the last elapsed month's cell, so the range runs from C5 to that cell.