18.11.2014 Views

Microsoft Office

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Part II<br />

Working with Formulas and Functions<br />

When you enter this formula, make sure that you use Ctrl+Shift+Enter (and don’t type the curly brackets).<br />

This formula works with two arrays, both of which are stored in cells. The first array is stored in B2:B7, and<br />

the second array is stored in C2:C7. The formula multiplies the corresponding values in these two arrays<br />

and creates a new array (which exists only in memory). The SUM function then operates on this new array<br />

and returns the sum of its values.<br />

NOTE<br />

In this case, you can use Excel’s SUMPRODUCT function to obtain the same result without using<br />

an array formula:<br />

=SUMPRODUCT(B2:B7,C2:C7)<br />

As you see, however, array formulas allow many other types of calculations that are otherwise not possible.<br />

Creating an array constant<br />

The examples in the preceding section used arrays stored in worksheet ranges. The examples in this section<br />

demonstrate an important concept: An array need not be stored in a range of cells. This type of array, which<br />

is stored in memory, is referred to as an array constant.<br />

To create an array constant, list its items and surround them with brackets. Here’s an example of a five-item<br />

vertical array constant:<br />

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

The following formula uses the SUM function, with the preceding array constant as its argument. The formula<br />

returns the sum of the values in the array (which is 3).<br />

=SUM({1,0,1,0,1})<br />

Notice that this formula uses an array, but the formula itself isn’t an array formula. Therefore, you don’t use<br />

Ctrl+Shift+Enter to enter the formula — although entering it as an array formula will still produce the same<br />

result.<br />

When you specify an array directly (as shown previously), you must provide the brackets<br />

around the array elements. When you enter an array formula, on the other hand, you do not<br />

supply the brackets.<br />

NOTE<br />

At this point, you probably don’t see any advantage to using an array constant. The formula that follows, for<br />

example, returns the same result as the previous formula:<br />

=SUM(1,0,1,0,1)<br />

The advantages, however, will become apparent.<br />

Following is a formula that uses two array constants:<br />

=SUM({1,2,3,4}*{5,6,7,8})<br />

This formula creates a new array (in memory) that consists of the product of the corresponding elements in<br />

the two arrays. The new array is<br />

{5,12,21,32}<br />

This new array is then used as an argument for the SUM function, which returns the result (70). The formula<br />

is equivalent to the following formula, which doesn’t use arrays:<br />

=SUM(1*5,2*6,3*7,4*8)<br />

316

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

Saved successfully!

Ooh no, something went wrong!