Sub topic 10
Finding the failing part with Trace Precedents and Evaluate Formula
This chapter assumes you can enter and edit formulas, use cell references and ranges such as A2 and A2:A10, and know the basics of SUM, AVERAGE and VLOOKUP. It also assumes you know the difference between numbers and text in a cell. The earlier chapters covered what each error value means. Here you learn two tools that show you which part of a formula produced the error.
Why you need a tool to locate the failure
An error value tells you the type of problem, but not where it started. A formula can combine several cell references, nested functions and lookups. If any one of them fails, the whole formula usually shows the same error.
Errors also travel. If A2 contains #DIV/0!, then =A2+10 shows #DIV/0! as well, and so does every formula that uses that result. The cell where you see the error may be several steps away from the cell that caused it.
Two tools on the Formulas tab, in the Formula Auditing group, help with this:
- Trace Precedents shows which cells feed a formula. Use it to find the input that holds the original error.
- Evaluate Formula calculates a formula one step at a time. Use it to find the part inside a single formula that fails.
A useful rule is to work from the outside in. Use Trace Precedents to find the cell where the error began, then use Evaluate Formula on that cell.
Trace Precedents
A precedent is a cell that a formula depends on. In =A2/B2, the cells A2 and B2 are precedents of the formula.
Using it
- Select the cell that shows the error.
- Go to Formulas, then Trace Precedents.
- Excel draws blue arrows from each precedent to the selected cell.
- Click Trace Precedents again to add the next level of precedents.
- When you finish, choose Remove Arrows in the same group.
The keyboard shortcut for Trace Precedents is Ctrl+[, which selects the precedents directly. It selects them instead of drawing arrows, but it is quick for jumping to the input cells.
Reading the arrows
- A solid blue arrow points from a precedent to the formula cell.
- If the precedent is a range, Excel draws a blue border around the whole range and one arrow from it.
- If an arrow turns red, the precedent contains an error. This is the most useful signal. Follow the red arrows back until you reach a cell that has an error but whose own precedents do not.
- A dashed black arrow with a worksheet icon means the precedent is on another sheet or in another workbook. Double-click the dashed arrow and choose the reference in the Go To list to jump to it.
Example
Suppose a small sales sheet has these cells:
| Cell | Content | Result |
|---|---|---|
| B2 | Units sold, typed by hand | 0 |
| C2 | `=A2/B2` (revenue per unit) | #DIV/0! |
| D2 | `=C2*1.2` (price with margin) | #DIV/0! |
| E2 | `=D2+5` (final price) | #DIV/0! |
The error appears in E2, and a formula like =D2+5 looks harmless. Select E2 and trace precedents. A red arrow leads to D2, and tracing again leads to C2. Tracing once more shows red arrows from neither A2 nor B2 (they hold plain values), so C2 is where the error starts. The divisor B2 is zero, and the fix from the #DIV/0! chapter applies there:
=IF(B2=0,"",A2/B2)Note that this returns an empty string. Formulas in D2 and E2 would then show #VALUE! because ""*1.2 is text multiplied by a number. Trace Precedents helps again here. It shows you that the new error in D2 now comes from C2. You would then guard D2 as well, or choose a different approach to the missing value. The final chapter of this tutorial covers when to prevent an error and when to mask it.
Trace Dependents and its limits
Trace Dependents works in the opposite direction. It shows which formulas use the selected cell. This is useful before you delete or change a cell, because it shows what could break (see the #REF! chapter).
Keep these limits in mind:
- Arrows do not show every kind of dependency. Names that refer to ranges, and some references built with
INDIRECTorOFFSET, may not be traced reliably. - Arrows disappear when you edit the sheet in some ways, such as inserting rows. Redraw them after changes.
- A very large number of arrows makes the sheet hard to read. Trace one level at a time.
Evaluate Formula
Trace Precedents works across cells. Evaluate Formula works inside one cell. It opens a dialog that shows the formula and lets you calculate it a piece at a time, in the same order Excel uses.
Using it
- Select the cell with the formula. Evaluate Formula works on one cell at a time.
- Go to Formulas, then Evaluate Formula.
- The dialog shows the formula with one part underlined. The underlined part is the next one Excel will calculate.
- Click Evaluate to replace the underlined part with its value.
- Click Step In to look inside a cell reference that holds a formula, or inside a nested function. Click Step Out to return.
- Continue until the result appears. The step where an error value first appears marks the failing part.
- Click Restart to run through it again, or Close when finished.
Example: a lookup that returns #N/A
Take this formula, with product codes in A2:A100 and prices in B2:B100:
=IFNA(VLOOKUP(E2,A2:B100,2,FALSE),"Not found")This formula already hides #N/A, so it will not show an error. Imagine it returns "Not found" for a product code you know exists. Evaluate Formula lets you see why without changing the formula:
- The first underlined part is
E2. Evaluate shows its value, such as"KB-104 ". The trailing space is visible inside the quotation marks. - The next step evaluates the VLOOKUP and returns #N/A, because no code in A2:A100 has that trailing space.
- IFNA then replaces #N/A with "Not found".
You have found the cause: a hidden space in E2. The repair is the one from the earlier chapter on stray spaces. Apply TRIM to the lookup value:
=IFNA(VLOOKUP(TRIM(E2),A2:B100,2,FALSE),"Not found")This is a good example of why you should test a formula before wrapping it in IFNA or IFERROR. A wrapper turns the error into a normal-looking result, so you lose the signal that something is wrong.
Example: a nested formula
Evaluate Formula is especially useful when functions are nested. Consider this formula, which is meant to return an average and then a rounded total:
=ROUND(AVERAGE(B2:B10)*SUM(A2,B2),1)If it returns #DIV/0!, step through it:
AVERAGE(B2:B10)is the first function evaluated. If B2:B10 has no numbers, Evaluate shows #DIV/0! at this step.- Every later step carries the error forward, so ROUND returns #DIV/0! as well.
You do not need to read the full formula to know that the empty range B2:B10 is the problem. Without the tool, you might have wrongly suspected SUM or ROUND.
What the order of evaluation shows
Evaluate Formula follows Excel's order of operations. It computes inner functions before outer ones, and it computes operators by precedence. It is common to be surprised by this order. For example, in =A2+B2*C2 the multiplication is computed first. Seeing the sequence on screen is a good way to find mistakes that do not produce an error value but give a wrong number.
Limits of Evaluate Formula
- It evaluates one cell at a time. It cannot step through a whole range of results.
- For a dynamic array formula that returns several values, it shows the array as a block, such as
{1;2;3}, which can be harder to read. Evaluate a smaller part of the formula if needed. - Volatile functions such as
NOWandRANDmay return a different value each time, so a step you see might not match the earlier result. - If a formula refers to a closed external workbook, Evaluate Formula may not be able to show the values from that workbook.
- You cannot edit the formula while the dialog is open. Close it, make the fix, and start again.
A related shortcut: evaluating a selection
You can also check part of a formula directly in the formula bar. Click in the formula bar, select a portion of the formula, and press F9. Excel replaces the selection with its calculated value.
Two cautions apply:
- The selection must be a complete, valid piece of the formula, such as a whole function with its closing bracket.
- If you press
EnterafterF9, the calculated value replaces the original text permanently. PressEscto leave the formula unchanged.
Putting both tools together
A reliable routine for an unknown error is:
- Read the error value and recall its likely causes.
- Select the cell and run Trace Precedents repeatedly until you find the earliest cell holding an error. Cells with red arrows are suspects.
- Select that cell and run Evaluate Formula. Note the step where the error first appears.
- Look at the values the failing step received. Check for zero or blank divisors, text where numbers are expected, extra spaces, deleted references and misspelled names.
- Fix the data or the formula at that point, not at the end of the chain.
- Remove the arrows and check that the downstream cells now show correct values.
Common mistakes
- Tracing only one level. The first set of arrows may show only an intermediate formula. Click Trace Precedents again to follow the chain.
- Forgetting that blanks are not errors. A blank precedent does not produce a red arrow, but it can still cause #DIV/0! or a wrong lookup result. Check the values that Evaluate Formula displays.
- Skipping the displayed value. In Evaluate Formula, read each result carefully. Quotation marks show text, so
"5"is text and5is a number. - Debugging a formula that already contains IFERROR. The wrapper hides the error, so Trace Precedents and Evaluate Formula may show nothing unusual at the top level. Evaluate the inner expression, or temporarily remove the wrapper.
Exercise
In a sheet, F2 contains =E2*2, E2 contains =D2+5, and D2 contains =A2/B2, where B2 is 0. F2 shows #DIV/0!. Which tool do you use first to find where the error starts, and which tool do you then use on the cell where it starts? What do you change?
Show answer
Use Trace Precedents first. Select F2 and trace until you reach D2, since A2 and B2 hold plain values and send no red arrows. Then select D2 and use Evaluate Formula to confirm that the division of A2 by B2 returns #DIV/0! because B2 is 0. Fix D2, for example with =IF(B2=0,"",A2/B2), or correct the value in B2. Then check E2 and F2, because an empty string in D2 would make them return #VALUE!.
Exercise
A formula =VLOOKUP(TRIM(E2),A2:B100,2,FALSE) returns #N/A, but you can see the code in column A. You step through it with Evaluate Formula. What would you look for at the first two steps?
Show answer
Look at the value of TRIM(E2) at the first step and check that it matches a code in A2:A100 exactly. Then look at the result of the VLOOKUP step. If the lookup value looks right, the stored codes in column A may contain extra spaces or be text where E2 is a number, or the reverse. Check the stored values in column A with Trace Precedents or by selecting those cells.
Exercise
You select part of a long formula in the formula bar and press F9 to see its value. How do you get back to the original formula?
Show answer
Press Esc. Pressing Enter would permanently replace the selected part of the formula with its calculated value.