Sub topic 10
Checking and editing a formula
This chapter assumes you can enter a formula that starts with =. It also assumes you know the operators + - * / ^ %, Excel's order of operations, relative and absolute references, and the meaning of #DIV/0!, #NAME? and #VALUE!. Here you will learn to confirm that a formula does what you meant, and to change it safely when it doesn't.
Why a formula needs checking
Excel runs any formula that is valid. It cannot tell whether the formula matches your intent. A formula with misplaced parentheses returns a clean number with no error, and that number is wrong. Checking means comparing the result with what you expect, then looking inside the formula when they differ.
Suppose B2 holds a price of 20, C2 holds a quantity of 3, and F1 holds a tax rate of 8%. You want the price with tax, and you type this:
=B2*1+$F$1Excel returns 20.08. The correct formula is below, and it returns 21.6:
=B2*(1+$F$1)The first formula multiplies before it adds, so it adds 0.08 to the price instead of adding 8% of the price. Nothing in the cell looks broken. Only a quick estimate shows the problem: 8% of 20 is about 1.60, so the answer should be near 21.60.
Look at the formula, not just the result
A cell shows its result. The formula itself appears in the formula bar when you select the cell. To see every formula on the sheet at once, press Ctrl+` (the backtick key, usually left of 1). Press it again to return to results.
Excel also helps when you enter edit mode. Select the cell and press F2, or double-click it. Each cell reference in the formula gets a color, and a matching colored border appears around that cell on the sheet. A border around the wrong cell shows a wrong reference immediately. Excel also colors matching parentheses as you type, so you can see which pair encloses which part.
Edit a formula
You have three ways to open a formula for editing:
- Select the cell and press F2.
- Double-click the cell.
- Select the cell and click in the formula bar.
Make your change, then finish in one of two ways:
- Press Enter to accept the edit. Excel recalculates.
- Press Esc to cancel. The cell returns to what it held before.
While you are editing, you can click a different cell on the sheet to change a reference. You can also drag a colored border to a new range. Press F4 with the cursor on a reference to cycle it through B2, $B$2, B$2 and $B2. This is the fastest way to fix a reference that should have been absolute.
Step through the calculation
Excel includes tools that show the order of calculation. They are on the Formulas tab.
| Tool | Where | What it shows |
|---|---|---|
| Show Formulas | Formulas tab, or Ctrl+` | Every formula on the sheet instead of its result |
| Evaluate Formula | Formulas tab, Formula Auditing group | The formula calculated one step at a time |
| Trace Precedents | Formulas tab, Formula Auditing group | Arrows from the cells the formula reads |
| Trace Dependents | Formulas tab, Formula Auditing group | Arrows to the cells that use this cell |
| Error Checking | Formulas tab, Formula Auditing group | Possible problems, with a suggested fix for each |
Evaluate Formula is the best tool for precedence mistakes. With the cell =B2*1+$F$1 selected, click Evaluate repeatedly. The formula changes like this:
B2*1+$F$120*1+$F$120*1+0.0820+0.0820.08
Step 4 shows the multiplication finishing before the addition, which is the cause of the wrong answer. You can then add the parentheses.
You can also test one piece. In edit mode, select part of the formula in the formula bar, such as 1+$F$1, and press F9. Excel replaces the selection with its value. Press Esc afterward, not Enter, because Enter would keep the typed value in place of your formula.
Check one error at a time
When a cell shows an error, select it. A small warning icon appears beside it, and its menu offers Help on this error and Show Calculation Steps. Use the error type to guide your search:
#DIV/0!: the divisor is 0 or empty. Select the cell holding the divisor, for example B2 in=A2/B2.#NAME?: Excel does not recognize some text. Look for a misspelled name or an unquoted word.#VALUE!: an operand is text that cannot be used in arithmetic. Check for a number stored as text, or a stray space.
Habits that prevent mistakes
- Estimate the result before you trust it.
- Test with simple numbers such as 10 and 2, where you can calculate the answer in your head.
- Copy the formula down and check the last row, not only the first.
- Change one thing per edit, so you know which change fixed the problem.
Exercise
Cell A1 holds 10 and B1 holds 5. The formula in C1 is =A1+B1/5, and it returns 11. You wanted the average of A1 and B1 as a quick check of the sum divided by 5. Which tool or key shows you the order Excel used, and what edit gives the intended result of 3?
Show answer
Select C1 and use Evaluate Formula on the Formulas tab. It shows B1/5 calculated first (giving 1), then added to 10, which gives 11. The intended formula is =(A1+B1)/5, which returns 3. Press F2, add the parentheses, and press Enter.
Exercise
You select part of a formula in the formula bar and press F9. Excel replaces it with a number. How do you leave edit mode without damaging the formula?
Show answer
Press Esc. This cancels the edit and restores the original formula. Pressing Enter would save the number in place of the selected part.