Escolar Documentos
Profissional Documentos
Cultura Documentos
To add the three smallest values, you could use a formula like this:
This formula works fine, but using an array formula is more efficient. The following array formula
returns the sum of the three smallest values in a range named Data:
{=SUM(SMALL(Data,{1,2,3}))}
The formula uses an array constant as the second argument for the SMALL function. This gener-
ates a new array, which consists of the three smallest values in the range. This array is then
passed to the SUM function, which returns the sum of the values in the new array.
Figure 14-14 shows an example in which the range A1:A10 is named Data. The SMALL function is
evaluated three times, each time with a different second argument. The first time, the SMALL
function has a second argument of 1, and it returns –5. The second time, the second argument for
the SMALL function is 2, and it returns 0 (the second-smallest value in the range). The third time,
the SMALL function has a second argument of 3, and returns the third-smallest value of 2.
Figure 14-14: An array formula returns the sum of the three smallest values in A1:A10.
{–5,0,2)
To count the number of text cells in a range, you need an array formula. The following array for-
mula uses the IF function to examine each cell in a range. It then creates a new array (of the same
size and dimensions as the original range) that consists of 1s and 0s, depending on whether the
cell contains text. This new array is then passed to the SUM function, which returns the sum of
the items in the array. The result is a count of the number of text cells in the range.
{=SUM(IF(ISTEXT(A1:D5),1,0))}
This general array formula type (that is, an IF function nested in a SUM function) is very
useful for counting. Refer to Chapter 7 for additional examples.
Figure 14-15 shows an example of the preceding formula in cell C7. The array created by the IF
function is as follows:
{0,1,1,1;1,0,0,0;1,0,0,0;1,0,0,0;1,0,0,0}
Figure 14-15: An array formula returns the number of text cells in the range.
Notice that this array contains four rows of three elements (the same dimensions as the range).
A variation on this formula follows:
{=SUM(ISTEXT(A1:D5)*1)}
This formula eliminates the need for the IF function and takes advantage of the fact that
TRUE * 1 = 1
and
FALSE * 1 = 0
There is no “best” way to convert Boolean values to numbers. Pick a method that you like and
use that. However, be aware of all three methods so that you can identify them in other people’s
spreadsheets.
=AVERAGE(D2:D15)
With an array formula, you can eliminate column D. The following array formula calculates the
average of the changes but does not require the formulas in column D:
{=AVERAGE(C2:C15-B2:B15)}
Figure 14-16: Without an array formula, calculating the average change requires intermediate formulas in
column D.
How does it work? The formula uses two arrays, the values of which are stored in two ranges
(B2:B15 and C2:C15). The formula creates a new array that consists of the differences between
each corresponding element in the other arrays. This new array is stored in Excel’s memory, not in
a range. The AVERAGE function then uses this new array as its argument and returns the result.
The new array consists of the following elements:
{11,15,–6,1,19,2,0,7,15,1,8,23,21,–11}
=AVERAGE({11,15,–6,1,19,2,0,7,15,1,8,23,21,–11})
{=MAX(C2:C15-B2:B15)}
The following array formula returns the smallest change (that is, the least improvement). This for-
mula returns –11, which represents Nancy’s test scores:
{=MIN(C2:C15–B2:B15)}
Figure 14-17 shows a worksheet that uses a lookup table to display a word that corresponds to an
integer. For example, looking up a value of 9 returns Nine from the lookup table in D1:E10. The
formula in cell C1 is
=VLOOKUP(B1,D1:E10,2,FALSE)
Figure 14-17: You can replace the lookup table in D1:E10 with an array constant.
You can use a two-dimensional array in place of the lookup range. The following formula returns
the same result as the previous formula, but it does not require the lookup range in D1:E1:
=VLOOKUP(B1,{1,”One”;2,”Two”;3,”Three”;4,”Four”;5,”Five”;
6,”Six”;7,”Seven”;8,”Eight”;9,”Nine”;10,”Ten”},2,FALSE)