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.

Introducing Array Formulas 17<br />

Figure 17.15 shows an example in which the range A1:A10 is named Data. The SMALL function is evaluated<br />

three times, each time with a different second argument. The first time, the SMALL function has a second<br />

argument of 1, and it returns –5. The second time, the second argument for the SMALL function is 2,<br />

and it returns 0 (the second smallest value in the range). The third time, the SMALL function has a second<br />

argument of 3 and returns the third smallest value of 2.<br />

FIGURE 17.15<br />

An array formula returns the sum of the three smallest values in A1:A10.<br />

Therefore, the array that’s passed to the SUM function is<br />

{-5,0,2)<br />

The formula returns the sum of the array (–3).<br />

Counting text cells in a range<br />

Suppose that you need to count the number of text cells in a range. The COUNTIF function seems like it<br />

might be useful for this task — but it’s not. COUNTIF is useful only if you need to count values in a range<br />

that meet some criterion (for example, values greater than 12).<br />

To count the number of text cells in a range, you need an array formula. The following array formula uses<br />

the IF function to examine each cell in a range. It then creates a new array (of the same size and dimensions<br />

as the original range) that consists of 1s and 0s, depending on whether the cell contains text. This new<br />

array is then passed to the SUM function, which returns the sum of the items in the array. The result is a<br />

count of the number of text cells in the range.<br />

CROSS-REF<br />

{=SUM(IF(ISTEXT(A1:D5),1,0))}<br />

This general array formula type (that is, an IF function nested in a SUM function) is very useful<br />

for counting. Refer to Chapter 14 for additional examples.<br />

Figure 17.16 shows an example of the preceding formula in cell C8. The array created by the IF function is<br />

{0,1,1,1;1,0,0,0;1,0,0,0;1,0,0,0;1,0,0,0}<br />

Notice that this array contains four rows of three elements (the same dimensions as the range).<br />

A slightly more efficient variation on this formula follows:<br />

{=SUM(ISTEXT(A1:D5)*1)}<br />

329

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

Saved successfully!

Ooh no, something went wrong!