Operators are often used together to build up complex formulae. In order to do this, you need to know which operator is used first in evaluating the expression. Rather than use layers of brackets to describe the order in which the expression should be evaluated, each operator is awarded a precedence rating. Those at the top of the list are evaluated first, working down towards those at the bottom. If a formula contains two operators of equal precedence, evaluation will be carried out from left to right.
1 | - | Unary minus |
( ) | Brackets | |
! | Unary NOT | |
2 | ^ | Raise to the power |
3 | * | Multiply |
/ | Divide | |
4 | + | Plus |
- | Minus | |
5 | = | Equals |
<> | Not equal to | |
< | Less than | |
> | Greater than | |
<= | Not greater than | |
>= | Not less than | |
6 | & | AND |
7 | | | OR |
The following formula shows how operator precedence affects an arithmetic formula using numeric constants; in practice the formula would be more likely to contain cell references than constants:
-3*2-2 evaluates as ((-3)*2)-2
The answer is -8.
The following example shows how operator precedence affects relational and logical operators:
IF(A1=3 & B1=4, SUM(A1:A10), 0)
The formula first evaluates the expression A1=3; if it is true, it then evaluates B1=4. If this is also true, the SUM operation is carried out.