Sub topic 10
Checking and Editing a Formula
This chapter assumes you can already enter a formula that starts with =, use cell references, and predict a result from operator precedence. It also assumes you know the difference between relative and absolute references from the copying chapter. Here you will learn how to inspect a formula you or someone else wrote, find out why it returns an unexpected result, and change it without breaking it.
Why checking is a separate skill
Excel does not tell you when a formula is wrong. It only tells you when a formula is impossible. =B2*C2 returns a number whether or not B2 and C2 are the cells you meant. A formula that gives a wrong but plausible number is more dangerous than one that shows #DIV/0!, because nobody notices it.
Checking a formula means answering three questions:
- What does the formula say? This means reading the exact text, not the displayed result.
- Which cells does it use? This means confirming the references point at the right inputs.
- In what order does it calculate? This means confirming precedence and parentheses do what you intended.
Editing is the follow-up: changing the formula and confirming the change did what you wanted.
Reading a formula: the formula bar and Show Formulas
A cell shows a result, but the cell holds a formula. To see the formula, select the cell and look at the formula bar, the long box above the column letters. The formula bar always shows what is stored in the active cell. A cell showing 20 might hold =(2+3)*4, =5*4, or the typed number 20. Only the formula bar tells you which.
If the formula bar is too short for a long formula, press Ctrl+Shift+U to expand it. You can also drag the arrow at its right edge downward.
When you need to review a whole sheet, selecting cells one at a time is slow. Press Ctrl+ (the grave accent, usually left of the 1 key) to switch to Show Formulas mode. Every cell then displays its formula instead of its result, and columns widen to fit. Press Ctrl+ again to switch back. The same toggle is under Formulas > Show Formulas.
Suppose a sheet looks like this in normal mode:
| Row | A | B | C | D |
|---|---|---|---|---|
| 1 | Item | Price | Qty | Total |
| 2 | Pen | 2.50 | 4 | 10.00 |
| 3 | Pad | 4.00 | 3 | 12.00 |
In Show Formulas mode, column D reveals what it contains:
| Row | D |
|---|---|
| 1 | Total |
| 2 | `=B2*C2` |
| 3 | `=B3*C3` |
Now you can see at a glance that the two rows follow the same pattern. A row with a different pattern, or a typed number where a formula should be, stands out immediately.
Seeing which cells a formula uses
Entering edit mode on a formula highlights its references. Select D2, then press F2 (or double-click the cell). Excel does three things:
- The formula appears in the cell, with the cursor at the end.
- Each reference in the formula is colored, and the matching cell on the sheet gets a border in the same color. Here B2 is one color and C2 is another.
- The status bar at the bottom left changes from Ready to Edit.
If a reference points at the wrong cell, you can fix it without retyping. Drag the colored border of the cell to a new cell, and Excel rewrites the reference in the formula. To enlarge or shrink a range reference, drag the small square on a corner of its border.
For a quicker, read-only view, use Ctrl+[ on a selected formula cell. It jumps the selection to the cells the formula directly uses. Press Esc or click anywhere to leave edit mode without changing anything.
Trace Precedents and Trace Dependents
Two buttons under Formulas > Formula Auditing draw arrows on the sheet.
- Trace Precedents draws blue arrows from the cells that feed the selected formula into it. This answers "where do the inputs come from?"
- Trace Dependents draws arrows from the selected cell to every formula that uses it. This answers "what breaks if I change this cell?"
Use Trace Dependents before you edit or delete an input cell. If you select F1 in the tax example =B2*(1+$F$1) and click Trace Dependents, you see an arrow to every price row that uses the tax rate. Click Remove Arrows when you are finished.
Checking the order of calculation
References tell you what goes in. You also need to know the order Excel calculates in. Excel has two built-in tools for this.
Evaluate Formula
Select the formula cell, then choose Formulas > Evaluate Formula. A dialog shows the formula with one part underlined. That part is what Excel will calculate next. Click Evaluate and Excel replaces the underlined part with its value, then underlines the next part.
Take =2+3*4. The steps look like this:
| Step | Dialog shows | Underlined part |
|---|---|---|
| Start | `=2+3*4` | `3*4` |
| After 1 click | `=2+12` | `2+12` |
| After 2 clicks | `=14` | none |
The underlined part at the start is 3*4, not 2+3. That is the precedence rule in action: multiplication is calculated before addition. With =(2+3)*4 the first underlined part is 2+3.
Evaluate Formula is most useful on formulas with several operators, where you cannot easily tell which part produced the wrong number. Click Step In only if the underlined part is itself a reference to another formula. For simple arithmetic you can ignore it.
Testing part of a formula with F9
You can also test a piece of a formula in the formula bar without opening a dialog:
- Select the cell and click in the formula bar.
- Highlight the part you want to test. For example, in
=B2*(1+$F$1)highlight(1+$F$1). - Press F9. The highlighted part is replaced by its value, for example
1.08. - Press Esc to cancel.
You must highlight a complete, valid piece. Highlighting 1+ without the next operand gives an error message, because the piece cannot be calculated on its own.
Checking parentheses
Parentheses are the most common source of editing mistakes, because a change often requires adding both a ( and a ). Excel helps in three ways:
- While you type or move the cursor with arrow keys, the pair of parentheses around the cursor is briefly highlighted.
- In nested parentheses, each level has its own color, so you can see which pairs belong together.
- If you press Enter with unbalanced parentheses, Excel shows a message that there is a problem with the formula. In some cases it offers a corrected version. Read the proposed fix before accepting it, because Excel places the missing
)at the end, which may not be where you meant it.
A balanced formula can still be wrong. Compare these two formulas:
=B2*(1+$F$1)
=B2*1+$F$1Both are valid. With B2 as 100 and F1 as 8%, the first returns 108. The second multiplies 100 by 1 and then adds 0.08, so it returns 100.08. Excel accepts both without complaint, so only a hand check catches the second.
Checking with a hand estimate
The most reliable check does not use an Excel tool at all. Before trusting a result, estimate it with rounded numbers in your head.
- Price 2.50, quantity 4: roughly 2.5 × 4 = 10. If the cell shows 10, good.
- Price 100 with 8% tax: should be a little over 100. If the cell shows 8 or 800, the formula is wrong.
Rounded estimates catch the typical errors: a missing parenthesis, a percent entered as 8 instead of 8%, a reference to the wrong row, or a relative reference that shifted when you copied it. The results of these errors are usually off by a large factor.
Another quick check is to change an input and see whether the result moves. If you change C2 from 4 to 5 and D2 does not change, D2 is not using C2. It may hold a typed number, or the workbook may be in manual calculation mode. In that mode, press F9 with a cell selected (not in edit mode) to recalculate the workbook.
Editing a formula
You have four ways to start editing the formula in the active cell.
| Method | What happens |
|---|---|
| Press F2 | Edits in the cell, cursor at the end |
| Double-click the cell | Edits in the cell, cursor where you clicked |
| Click in the formula bar | Edits in the formula bar |
| Retype the whole formula | Replaces the old content |
Whichever you choose, you finish in one of two ways:
- Enter (or Tab, or clicking the check mark in the formula bar) saves the change.
- Esc (or clicking the X in the formula bar) cancels and keeps the original.
Esc is your safety net. If you are partway through an edit and unsure, press Esc and start again. Once you have pressed Enter, use Ctrl+Z to undo.
Enter mode and Edit mode
While editing, the status bar shows either Enter or Edit, and the arrow keys behave differently:
- In Enter mode (you started by typing directly into a cell), an arrow key picks a cell and inserts its reference into the formula. This is handy when building a formula by pointing at cells.
- In Edit mode (you started with F2 or a double-click), arrow keys move the cursor within the text.
If the arrow keys do something you did not expect, look at the status bar. Press F2 to switch between the two modes.
Editing a formula that was copied down a column
Every copy of a formula is an independent formula. Suppose D2:D50 all hold copies of =B2*C2, and you realize they should include tax. Editing D2 changes only D2. The standard approach is:
- Edit D2 so it reads
=B2*C2*(1+$F$1), then press Enter. - Select D2 to D50 (D2 first, then Shift+click D50).
- Press Ctrl+D to fill the formula down. The relative references B2 and C2 shift for each row, and
$F$1stays fixed.
Check that the reference to the tax rate is absolute before you fill. If you had written F1 without dollar signs, row 3 would point at F2, which is blank, and every row below would silently calculate without tax. Press F4 while the cursor is on or inside a reference to cycle it through F1, $F$1, F$1, and $F1.
After filling down, select the last cell and read its formula in the formula bar. If D50 reads =B50*C50*(1+$F$1), the fill worked.
Replacing a formula with its value
Sometimes you want to keep the result and discard the formula, for example when you are sending numbers to someone who should not see the calculation. Copy the cell, then use Paste Special > Values. Be careful: this is a one-way change. The value no longer updates when inputs change.
Signs that a formula needs attention
Excel marks some suspicious cells with a small green triangle in the top-left corner. Select the cell and an icon appears. Pointing at it explains the issue. Two common flags in simple arithmetic sheets are:
- Inconsistent formula. The cell's formula differs from the pattern of its neighbors. For example, D4 holds
=B4*C3while D3 and D5 follow=B*Con the same row. This is often a real mistake. - Number stored as text. A cell looks like a number but is text, which can cause
#VALUE!or silently exclude the value from other calculations.
The green triangle is a hint, not proof. A formula may be flagged and correct, or wrong and not flagged. Use the hint as a prompt to apply the checks in this chapter.
Three other situations come up often when editing:
- The formula shows as text. If a cell displays
=B2*C2instead of a result, the cell was formatted as Text before you typed, or you typed a leading apostrophe. Change the format to General, then press F2 and Enter to re-enter the formula. - A leading
=is missing.B2*C2is just text. Add the=. - The result is correct but displays oddly. A result of
0.08showing as8%is a number format, not a formula problem. Check the number format on the Home tab before changing the formula.
Matching the error to the check
The earlier chapter on errors covered what #DIV/0!, #NAME?, and #VALUE! mean. Here is which check finds the cause fastest.
| Error | Likely cause | Fastest check |
|---|---|---|
| `#DIV/0!` | A divisor cell is 0 or empty | Trace Precedents, then read the divisor cell's value |
| `#NAME?` | A typo or unknown name in the formula | Read the formula bar for misspelled text |
| `#VALUE!` | A reference holds text where a number is needed | Select each referenced cell; look for text alignment or a green triangle |
For example, =A2/B2 returns #DIV/0! when B2 is empty. Select the cell, press Ctrl+[ to jump to B2, and see the empty cell. The fix is to enter a value in B2, not to edit the formula.
A worked review
You inherit this sheet. The goal is a price with 8% tax in column D, using the tax rate in F1.
| Row | B | C | D | F |
|---|---|---|---|---|
| 1 | Price | Qty | Total with tax | Tax rate: 8% |
| 2 | 100 | 1 | 108 | |
| 3 | 50 | 2 | 100.08 |
Row 3 should give about 108, because 50 × 2 = 100 and 8% tax is 8. The cell shows 100.08, which fails the hand estimate. Follow the loop:
- Select D3 and read the formula bar. It says
=B3*C3+$F$1. - Row 2 uses a different pattern. Select D2 and read
=B2*C2*(1+$F$1). - D3 adds 0.08 instead of multiplying by 1.08. This is a precedence and parentheses mistake, not a reference mistake.
- Select D3, press F2, and rewrite the formula to match row 2:
=B3*C3*(1+$F$1)- Press Enter. D3 now shows 108, matching the estimate.
- Change F1 to 10%. Both rows should update. If one does not, it does not use F1.
Key points
- The formula bar shows what a cell contains. The cell shows only the result.
- Ctrl+` shows every formula on the sheet at once.
- F2 puts the cell in edit mode and highlights the cells the formula uses.
- Evaluate Formula steps through the calculation order, and F9 on a highlighted part tests one piece.
- Press Esc after testing with F9, and Esc to cancel an edit you are unsure about.
- A rounded hand estimate catches the mistakes that Excel will not flag.
- After editing a formula, copy it to its neighbors, then check the last one.
Exercise
Cell D5 holds =B5*(1+F1). You copy it from D5 down to D6, and D6 shows the same total as a row with no tax. You select D6 and read =B6*(1+F2). What went wrong, and what is the fix?
Show answer
F1 is a relative reference, so it shifted to F2 when the formula was copied down one row. F2 is empty and counts as 0, so the tax is 0. Edit D5 so it reads =B5*(1+$F$1) (press F4 with the cursor on F1 to add the dollar signs), then fill the formula down again with Ctrl+D.
Exercise
You select part of =B2*(1+$F$1) in the formula bar, press F9, and then press Enter. What has happened to the formula, and how do you recover?
Show answer
The selected part was replaced by its calculated value, for example =B2*1.08, and saved that way. The formula no longer follows F1. Press Ctrl+Z to undo, or retype the formula. In future, press Esc after testing a part with F9.
Exercise
A cell contains =10+5*2. Before pressing Enter you expected 30, but the cell shows 20. Name two tools that would show you why, and say what the first underlined step in Evaluate Formula would be.
Show answer
Evaluate Formula (Formulas > Evaluate Formula) and F9 on a highlighted part of the formula in the formula bar. The first underlined part in Evaluate Formula is 5*2, because multiplication is calculated before addition, giving =10+10, which is 20. To get 30, write =(10+5)*2.
Exercise
You change C2 from 4 to 5, but D2, which should use C2, does not change. Give two possible causes and how to check each.
Show answer
First, D2 may hold a typed number instead of a formula. Select D2 and read the formula bar. Second, the workbook may be in manual calculation mode. Press F9 with a cell selected (not in edit mode) to recalculate. A third possibility is that the formula refers to a different cell. Press F2 on D2 and check which cells are highlighted.