Page 359 - Excel 2007 Bible
P. 359
22_044039 ch17.qxp 11/21/06 11:08 AM Page 316
Part II
Working with Formulas and Functions
When you enter this formula, make sure that you use Ctrl+Shift+Enter (and don’t type the curly brackets).
This formula works with two arrays, both of which are stored in cells. The first array is stored in B2:B7, and
the second array is stored in C2:C7. The formula multiplies the corresponding values in these two arrays
and creates a new array (which exists only in memory). The SUM function then operates on this new array
and returns the sum of its values.
In this case, you can use Excel’s SUMPRODUCT function to obtain the same result without using
NOTE
NOTE
an array formula:
=SUMPRODUCT(B2:B7,C2:C7)
As you see, however, array formulas allow many other types of calculations that are otherwise not possible.
Creating an array constant
The examples in the preceding section used arrays stored in worksheet ranges. The examples in this section
demonstrate an important concept: An array need not be stored in a range of cells. This type of array, which
is stored in memory, is referred to as an array constant.
To create an array constant, list its items and surround them with brackets. Here’s an example of a five-item
vertical array constant:
{1,0,1,0,1}
The following formula uses the SUM function, with the preceding array constant as its argument. The for-
mula returns the sum of the values in the array (which is 3).
=SUM({1,0,1,0,1})
Notice that this formula uses an array, but the formula itself isn’t an array formula. Therefore, you don’t use
Ctrl+Shift+Enter to enter the formula — although entering it as an array formula will still produce the same
result.
NOTE When you specify an array directly (as shown previously), you must provide the brackets
NOTE
around the array elements. When you enter an array formula, on the other hand, you do not
supply the brackets.
At this point, you probably don’t see any advantage to using an array constant. The formula that follows, for
example, returns the same result as the previous formula:
=SUM(1,0,1,0,1)
The advantages, however, will become apparent.
Following is a formula that uses two array constants:
=SUM({1,2,3,4}*{5,6,7,8})
This formula creates a new array (in memory) that consists of the product of the corresponding elements in
the two arrays. The new array is
{5,12,21,32}
This new array is then used as an argument for the SUM function, which returns the result (70). The formula
is equivalent to the following formula, which doesn’t use arrays:
=SUM(1*5,2*6,3*7,4*8)
316

