18.11.2014 Views

Microsoft Office

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Performing Magic with Array Formulas 18<br />

Determining the closest value in a range<br />

The array formula that follows returns the value in a range named Data that is closest to another value<br />

(named Target):<br />

{=INDEX(Data,MATCH(SMALL(ABS(Target-Data),1),ABS(Target-Data),0))}<br />

If two values in the Data range are equidistant from the Target value, the formula returns the first one in the<br />

list. Figure 18.7 shows an example of this formula. In this case, the Target value is 45. The array formula in<br />

cell D5 returns 48 — the value closest to 45.<br />

FIGURE 18.7<br />

An array formula returns the closest match.<br />

Returning the last value in a column<br />

Suppose that you have a worksheet that you update frequently by adding new data to columns. You may<br />

need a way to reference the last value in column A (the value most recently entered). If column A contains<br />

no empty cells, the solution is relatively simple and doesn’t require an array formula:<br />

=OFFSET(A1,COUNTA(A:A)-1,0)<br />

This formula uses the COUNTA function to count the number of nonempty cells in column A. This value<br />

(minus 1) is used as the second argument for the OFFSET function. For example, if the last value is in row<br />

100, COUNTA returns 100. The OFFSET function returns the value in the cell 99 rows down from cell A1 in<br />

the same column.<br />

If column A has one or more empty cells interspersed, which is frequently the case, the preceding formula<br />

won’t work because the COUNTA function doesn’t count the empty cells.<br />

343

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!