11.08.2013 Views

Excel's Formula - sisman

Excel's Formula - sisman

Excel's Formula - sisman

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table 21-1: Operator Precedence in Excel <strong>Formula</strong>s<br />

Chapter 21: Tools and Methods for Debugging <strong>Formula</strong>s 583<br />

Symbol Operator Precedence<br />

– Negation 1<br />

% Percent 2<br />

^ Exponentiation 3<br />

* and / Multiplication and division 4<br />

+ and – Addition and subtraction 5<br />

& Text concatenation 6<br />

=, , and Comparison 7<br />

When in doubt (or when you simply need to clarify your intentions), use parentheses to ensure<br />

that operations are performed in the correct order. For example, the following formula multiplies<br />

A1 by A2, and then adds 1 to the result. The multiplication is performed first because it has a<br />

higher order of precedence.<br />

=1+A1*A2<br />

The following is a clearer version of this formula. The parentheses aren’t necessary — but in this<br />

case, the order of operations is perfectly obvious.<br />

=1+(A1*A2)<br />

Notice that the negation operator symbol is exactly the same as the subtraction operator symbol.<br />

This, as you may expect, can cause some confusion. Consider these two formulas:<br />

=–3^2<br />

=0–3^2<br />

The first formula, as expected, returns 9. The second formula, however, returns –9. Squaring a<br />

number always produces a positive result, so how is it that Excel can return the –9 result?<br />

In the first formula, the minus sign is a negation operator and has the highest precedence.<br />

However, in the second formula, the minus sign is a subtraction operator, which has a lower<br />

precedence than the exponentiation operator. Therefore, the value 3 is squared, and the result<br />

is subtracted from zero, producing a negative result.<br />

Excel is a bit unusual in interpreting the negation operator. Other spreadsheet products<br />

(for example, Lotus 1-2-3 and Quattro Pro) return –9 for both formulas. In addition,<br />

Excel’s VBA language also returns –9 for these expressions.

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

Saved successfully!

Ooh no, something went wrong!