INDEX returns cells inside a specified range
INDEX returns the cells specified by a row and column number. The row and column number are relative to the upper left corner of the specified reference range. For example, using =INDEX(B2:D3; 1; 1) returns the cell B2. Table 14 lists shows the syntax for using the INDEX function.
Table 14. Syntax for INDEX.
Syntax
| Description
|
INDEX(reference)
| Return the entire range.
|
INDEX(reference; row)
| Returns the specified row in the range.
|
INDEX(reference; row; column)
| Returns the cell specified by row and column. A row and column of 1 returns the cell in the upper left corner of the range.
|
INDEX(reference; row; column; range)
| A reference range can contain multiple ranges. The range argument specifies which range to use.
|
The INDEX function can return an entire range, a row, or a single column (see Table 14). The ability to index based on the start of the reference range provides some interesting uses. Using the values shown in Table 1, Listing 12 finds and returns Bob’s quiz scores. Table 15 contains a listing of each function used in Listing 12.
Listing 12. Return Bob’s quiz scores.
=SUM(OFFSET(INDEX(A2:G16; MATCH("Bob"; A2:A16; 0)); 0; 3; 1; 2))
Table 15. Breakdown of Listing 12.
Function
| Description
|
MATCH("Bob";A2:A16; 0)
| Returns 3 because Bob is the third entry in column A2:A16.
|
INDEX(A2:A16; 3)
| Returns the A4:G4—the row containing Bob’s quiz scores.
|
OFFSET(A4:G4; 0; 3; 1; 2)
| Returns the range D4:E4.
|
SUM(D4:E4)
| Returns the sum of Bob’s quiz scores.
|
 | A simple range contains one contiguous rectangular region of cells. It is possible to define a multi-range that contains multiple simple ranges. If the reference consists of multiple ranges, you must enclose the reference or range name in parentheses.
|
If reference argument to the INDEX function is a multi-range, then the range argument specifies which simple range to use (see Table 16).
Table 16. Using INDEX with a multi-range.
Function
| Returns
|
=INDEX(B2:G2; 1; 2)
| 93
|
=INDEX(B5:G5; 1; 2)
| 65
|
=INDEX((B2:G2;B5:G5); 1; 2)
| 93
|
=INDEX((B2:G2;B5:G5); 1; 2; 1)
| 93
|
=INDEX((B2:G2;B5:G5); 1; 2; 2)
| 65
|