Sub topic 8
Entering formulas with an equals sign
This chapter assumes you can select cells, type into them, and commit an entry with Enter. It also assumes you know how Excel decides between text and numbers. Here you will learn how a formula entry differs from other entries, how to build formulas by typing and by pointing, and which errors beginners meet most often.
What makes an entry a formula
Excel treats an entry as a formula when it begins with an equals sign (=). Everything after the sign is an expression for Excel to evaluate. The cell then shows the result, and the formula bar shows the formula itself.
Type this into C2, with numbers already in A2 and B2, and press Enter:
=A2*B2C2 now shows the product of A2 and B2. Select C2 again and the formula bar shows =A2*B2. The cell holds the formula, and the result is only what it displays. This is the stored-versus-displayed split from the previous chapter, applied to formulas.
Excel also accepts a plus or minus sign as a first character, so +A2*B2 works, and Excel adds the equals sign for you. Use the equals sign anyway. It is the standard form, and it avoids surprises when the entry begins with a minus sign.
Operators and precedence
A formula combines values with operators. Excel evaluates them in a fixed order.
| Operator | Meaning | Example | Result |
|---|---|---|---|
| `^` | Exponent | `=2^3` | 8 |
| `*` and `/` | Multiply and divide | `=6/2*3` | 9 |
| `+` and `-` | Add and subtract | `=2+3*4` | 14 |
| `&` | Join text | `="Q"&1` | Q1 |
| `=`, `<`, `>`, `<=`, `>=`, `<>` | Compare | `=5>3` | TRUE |
Excel evaluates the exponent first, then multiplication and division, then addition and subtraction. Operators at the same level run from left to right. Parentheses override the order, so =(2+3)*4 gives 20.
A common mistake is =A1+B1/2 when you meant the average. Division runs first, so Excel adds A1 to half of B1. Write =(A1+B1)/2 instead.
Three ways to put references into a formula
A reference is the address of a cell, such as B2, or of a range, such as B2:B9. You can supply references in three ways.
- Type them. Fast when you know the address.
- Point to them. After typing
=, click a cell or drag across a range. Excel inserts the address. - Use the arrow keys. After typing
=, press an arrow key to move a marker cell, and Excel inserts the address it lands on.
Pointing avoids typos in addresses, and it makes the cells you used visible. While you edit, Excel colors each reference in the formula and draws a border of the same color around the matching cell. If a border surrounds the wrong cell, you can see the mistake before you commit.
Entering a formula by pointing
- Click C2.
- Type
=. - Click A2. The formula reads
=A2. - Type
*. - Click B2. The formula reads
=A2*B2. - Press Enter.
If you type a character that is not an operator while the pointer marks a cell, Excel keeps the reference and continues. If you click a cell when the formula expects an operator, Excel may replace the previous reference. Type the operator first, then click.
Entering a function
A function is a named calculation that takes arguments in parentheses. SUM adds the values in its arguments:
=SUM(B2:B9)As you type a function name, Excel lists matching names. Press Tab to accept the highlighted name. Excel adds the opening parenthesis, and a tooltip shows the arguments the function expects. Type the arguments, then close the parenthesis. Excel usually supplies a missing closing parenthesis when you press Enter, but do not rely on this for nested functions, where it can close in the wrong place.
Text arguments go in double quotes, and a comma or semicolon separates arguments. The separator depends on your regional settings. If a formula copied from a web page is rejected, check whether your system expects semicolons.
The formula from the spine that pads a number with zeros is a function entry:
=TEXT(A1,"00000")If A1 holds 123, the result is the text 00123. It is an alternative to typing an apostrophe before the digits. The result is text, so you cannot add it up directly without converting it back.
Committing and canceling formula entries
Enter, Tab, and Esc behave as they do for other entries, with one addition. While you build a formula, the arrow keys move the reference marker rather than the cell cursor. This is called Point mode. The status bar shows "Point" while it is active.
Point mode catches many people out. If you type =A2* and then press an arrow key, Excel inserts a reference and does not move to another cell. To move the cell cursor, commit the formula first or press F2 to switch to Edit mode, in which the arrow keys move the text cursor inside the formula.
Press Esc to cancel a formula you have not yet committed. The cell keeps its previous contents.
Formulas that Excel shows as text
Sometimes a formula appears literally in the cell, as =A2*B2, instead of a result. There are two common causes.
- The cell is formatted as Text. Excel stores everything typed into a Text-formatted cell as text, even when it starts with
=. Change the format to General, then re-enter the formula. Pressing F2 and then Enter is enough. - An apostrophe or space comes first. An entry such as
'=A2*B2is text by design, and a leading space also stops Excel from reading it as a formula.
Turning on Show Formulas (Ctrl+` on the Formulas tab) also shows every formula in place of its result. Turn it off if you did not intend this.
Reading formula errors
If Excel cannot calculate a formula, the cell shows an error value that begins with #.
| Error | Common cause |
|---|---|
| `#DIV/0!` | Division by zero or by an empty cell |
| `#NAME?` | Misspelled function name, or text that is missing its quotes |
| `#VALUE!` | An operand of the wrong type, such as `=A1+B1` where B1 holds text |
| `#REF!` | A reference points to a cell that was deleted |
| `#N/A` | A lookup found no match |
| `#####` | The column is too narrow for the result. This is not a formula error |
Select the cell and look at the formula bar, then use the colored borders to check each reference. A green triangle in the corner of the cell means Excel has flagged a possible problem, such as a formula that differs from its neighbors. Hover over the marker for an explanation.
Circular references
A formula that refers to its own cell, directly or through other cells, creates a circular reference. For example, entering =A1+1 in A1 does this. Excel warns you when you commit it. Remove the self-reference. Intentional circular calculations require turning on iterative calculation in the options, which is rarely what a beginner wants.
Relative and absolute references
By default, a reference is relative. If you copy =A2*B2 from C2 to C3, it becomes =A3*B3, because the reference keeps its position relative to the formula. This is what makes the fill handle useful for formulas.
A dollar sign fixes part of a reference. Press F4 while the marker is on a reference to cycle through the forms.
| Form | Behavior when copied |
|---|---|
| `A2` | Row and column both shift |
| `$A$2` | Neither shifts |
| `A$2` | Row stays, column shifts |
| `$A2` | Column stays, row shifts |
If every row needs to use the same tax rate stored in F1, write =A2*$F$1. Without the dollar signs, the copied formula in row 3 would point to F2, which is probably empty and gives a result of 0.
Recalculation and what gets stored
Excel recalculates a formula whenever a cell it depends on changes. You do not need to re-enter it. If a workbook is set to manual calculation, results go stale until you press F9. The Calculation Options on the Formulas tab show which mode is active. When a result looks wrong and the inputs are correct, check this setting.
To keep a result and discard the formula, copy the cell and use Paste Special with Values. You can also press F2, then F9, then Enter, which replaces the formula in that one cell with its current value. This cannot be reversed without Undo, so be sure you want a fixed number.
Practical habits
- Build a formula by pointing when it references other cells, so the colored borders confirm your choices.
- Test a new formula on one row before filling it down.
- Use parentheses when the order is unclear, even if they are not required.
- Put constants such as tax rates in their own cells and refer to them with absolute references, instead of typing them into formulas.
- Check the formula bar, not only the cell, when a result looks suspicious.
Exercise
In A1 you type 10, and in B1 you type 5. You enter =A1+B1/5 in C1 and get 11, but you wanted the sum divided by 5. What formula do you enter instead, and why did the first one give 11?
Show answer
Enter =(A1+B1)/5, which gives 3. Excel divides before it adds, so the first formula calculated B1/5 = 1 and then added A1 (10), giving 11. The parentheses force the addition to run first.
Exercise
You type =A2*B2 in a cell, press Enter, and the cell displays =A2*B2 instead of a number. Give two possible causes and the fix for the most likely one.
Show answer
The cell may be formatted as Text, or the entry may begin with an apostrophe or a space. The most likely cause is the Text format. Change the format to General, then press F2 and Enter to re-enter the formula so Excel evaluates it.
Exercise
Column A holds prices and F1 holds a tax rate. You enter =A2*F1 in B2 and fill it down. B3 shows 0. What went wrong, and what formula should B2 contain?
Show answer
The reference F1 is relative, so in B3 it became F2, which is empty. Use an absolute reference: =A2*$F$1. You can press F4 after pointing at F1 to add the dollar signs.