Page 386 - Excel 2007 Bible
P. 386

23_044039 ch18.qxp  11/21/06  11:09 AM  Page 343
                                                                                    Performing Magic with Array Formulas
                                             Determining the closest value in a range
                                             The array formula that follows returns the value in a range named Data that is closest to another value
                                             (named Target):
                                                 {=INDEX(Data,MATCH(SMALL(ABS(Target-Data),1),ABS(Target-Data),0))}
                                             If two values in the Data range are equidistant from the Target value, the formula returns the first one in the
                                             list. Figure 18.7 shows an example of this formula. In this case, the Target value is 45. The array formula in
                                             cell D5 returns 48 — the value closest to 45.
                                       FIGURE 18.7
                                     An array formula returns the closest match.








                                             Returning the last value in a column                                            18
                                             Suppose that you have a worksheet that you update frequently by adding new data to columns. You may
                                             need a way to reference the last value in column A (the value most recently entered). If column A contains
                                             no empty cells, the solution is relatively simple and doesn’t require an array formula:
                                                 =OFFSET(A1,COUNTA(A:A)-1,0)
                                             This formula uses the COUNTA function to count the number of nonempty cells in column A. This value
                                             (minus 1) is used as the second argument for the OFFSET function. For example, if the last value is in row
                                            100, COUNTA returns 100. The OFFSET function returns the value in the cell 99 rows down from cell A1 in
                                            the same column.
                                            If column A has one or more empty cells interspersed, which is frequently the case, the preceding formula
                                            won’t work because the COUNTA function doesn’t count the empty cells.





                                                                                                                      343
   381   382   383   384   385   386   387   388   389   390   391