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 />

The SUM function can take up to 255 arguments. The following formula, for example, returns the sum of<br />

the values in five noncontiguous ranges:<br />

=SUM(A1:A9,C1:C9,E1:E9,G1:G9,I1:I9)<br />

You can use complete rows or columns as an argument for the SUM function. The formula that follows, for<br />

example, returns the sum of all values in column A. If this formula appears in a cell in column A, it generates<br />

a circular reference error.<br />

=SUM(A:A)<br />

The following formula returns the sum of all values on Sheet1 by using a range reference that consists of all<br />

rows. To avoid a circular reference error, this formula must appear on a sheet other than Sheet1.<br />

=SUM(Sheet1!1:1048576)<br />

The SUM function is very versatile. The arguments can be numerical values, cells, ranges, text representations<br />

of numbers (which are interpreted as values), logical values, and even embedded functions. For example,<br />

consider the following formula:<br />

=SUM(B1,5,”6”,,SQRT(4),A1:A5,TRUE)<br />

This odd formula, which is perfectly valid, contains all of the following types of arguments, listed here in<br />

the order of their presentation:<br />

n<br />

n<br />

n<br />

n<br />

n<br />

n<br />

n<br />

A single cell reference<br />

A literal value<br />

A string that looks like a value<br />

A missing argument<br />

An expression that uses another function<br />

A range reference<br />

A logical TRUE value<br />

The SUM function is versatile, but it’s also inconsistent when you use logical values (TRUE or<br />

FALSE). Logical values stored in cells are always treated as 0. But logical TRUE, when used as<br />

an argument in the SUM function, is treated as 1.<br />

CAUTION<br />

Computing a cumulative sum<br />

You may want to display a cumulative sum of values in a range — sometimes known as a “running total.”<br />

Figure 14.11 illustrates a cumulative sum. Column B shows the monthly amounts, and column C displays<br />

the cumulative (year-to-date) totals.<br />

The formula in cell C2 is<br />

=SUM(B$2:B2)<br />

Notice that this formula uses a mixed reference — that is, the first cell in the range reference always refers to<br />

the same row (in this case, row 2). When this formula is copied down the column, the range argument<br />

adjusts such that the sum always starts with row 2 and ends with the current row. For example, after copying<br />

this formula down column C, the formula in cell C8 is<br />

=SUM(B$2:B8)<br />

266

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

Saved successfully!

Ooh no, something went wrong!