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

You can use parentheses to override the Excel’s built-in order of precedence. Expressions within parentheses<br />

are always evaluated first.<br />

The following formula uses parentheses to control the order in which the calculations occur. In this case,<br />

cell B3 is subtracted from cell B2 and the result is multiplied by cell B4:<br />

=(B2-B3)*B4<br />

If you enter the formula without the parentheses, Excel computes a different answer. Because multiplication<br />

has a higher precedence, cell B3 is multiplied by cell B4. Then this result is subtracted from cell B2, which<br />

isn’t what was intended.<br />

The formula without parentheses looks like this:<br />

=B2-B3*B4<br />

It’s a good idea to use parentheses even when they aren’t strictly necessary. Doing so helps to clarify what<br />

the formula is intended to do. For example, the following formula makes it perfectly clear that B3 should be<br />

multiplied by B4, and the result subtracted from cell B2. Without the parentheses, you would need to<br />

remember Excel’s order of precedence.<br />

=B2-(B3*B4)<br />

You can also nest parentheses within formulas — that is, put them inside other parentheses. If you do so,<br />

Excel evaluates the most deeply nested expressions first — and then works its way out. Here’s an example of<br />

a formula that uses nested parentheses:<br />

=((B2*C2)+(B3*C3)+(B4*C4))*B6<br />

This formula has four sets of parentheses — three sets are nested inside the fourth set. Excel evaluates each<br />

nested set of parentheses and then sums the three results. This result is then multiplied by the value in B6.<br />

Although the preceding formula uses four sets of parentheses, only the outer set is really necessary. If you<br />

understand operator precedence, it should be clear that you can rewrite this formula as:<br />

=(B2*C2+B3*C3+B4*C4)*B6<br />

Again, using the extra parentheses makes the calculation much clearer.<br />

Every left parenthesis, of course, must have a matching right parenthesis. If you have many levels of nested<br />

parentheses, keeping them straight can sometimes be difficult. If the parentheses don’t match, Excel displays<br />

a message explaining the problem — and won’t let you enter the formula.<br />

In some cases, if your formula contains mismatched parentheses, Excel may propose a correction to your<br />

formula. Figure 11.1 shows an example of the Formula AutoCorrect feature. You may be tempted simply to<br />

accept the proposed correction, but be careful — in many cases, the proposed formula, although syntactically<br />

correct, isn’t the formula you intended, and it will produce an incorrect result.<br />

178

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

Saved successfully!

Ooh no, something went wrong!