Sub topic 10
Check Cells and Error Flags
What this chapter assumes
You should already know how to write Excel or Google Sheets formulas, apply conditional formatting, and read a basic balance sheet. You should also know that a forecast model has historical and projected columns. This chapter covers the formulas that test a model's internal consistency, the formatting that makes a failed test visible, and the ways checks go wrong.
Why checks exist
Colours, signs, and labels help a reviewer read a model. They do not tell the reviewer whether the model is right. A check cell is a formula that tests something that must be true if the model is working, such as "total assets equal total liabilities plus equity", and reports the result in a fixed format.
A check cell has three jobs:
- It catches errors when they are introduced, not weeks later.
- It tells a reviewer where to look first.
- It gives the next user evidence that the numbers still hold together after they changed an input.
A check can only prove that something is wrong. A model with all checks passing can still be wrong, because the checks only test what you thought to test.
Anatomy of a check cell
The most common convention is that a check returns 0 when it passes and 1 when it fails. Using the same output everywhere lets you add all checks together, and a total of 0 means every check passed.
Balance check (row 60): =IF(ABS(D40-D55)<0.001,0,1)
Conditional format on row 60: red fill when the cell value is 1
Summary cell on cover sheet: =SUM(D60:N60) (0 means all checks pass)Three details in this formula matter.
- ABS makes the test work in both directions. Without it,
D40-D55<0.001passes whenever liabilities and equity exceed assets by any amount, because the difference is a large negative number. - The tolerance (0.001) replaces an exact
=0comparison. Spreadsheets store numbers in binary floating point, so two values that are equal on paper can differ by a tiny amount after many calculations. An exact comparison can fail with no real error. - The output is 0 or 1, not TRUE or FALSE. Numbers can be summed, counted, and tested with a single comparison. Text results such as "OK" and "ERROR" cannot be added.
Choosing the tolerance
The tolerance has to be small relative to the model's units. If the model is in millions, 0.001 means one thousand currency units, which is small enough to catch real errors. If the model is in single currency units, 0.001 is much stricter than any rounding in the model needs. Pick a tolerance that is smaller than the smallest error you care about and larger than the rounding noise. Put it in one input cell, formatted as an input, and have every check refer to it, instead of typing 0.001 into each formula.
Which checks to include
A model rarely needs dozens of checks. It needs the ones that test the places where models break.
| Check | What it tests | Typical formula |
|---|---|---|
| Balance sheet balances | Assets equal liabilities plus equity in every period | `=IF(ABS(Assets-LiabEquity)<Tol,0,1)` |
| Cash reconciles | Closing cash on the cash flow statement equals cash on the balance sheet | `=IF(ABS(CF_Close-BS_Cash)<Tol,0,1)` |
| Subtotals add up | A reported total equals the sum of its parts | `=IF(ABS(Total-SUM(Parts))<Tol,0,1)` |
| Sources equal uses | Funding raised equals spending in a transaction | `=IF(ABS(Sources-Uses)<Tol,0,1)` |
| Debt schedule | Closing debt is not negative and matches the balance sheet | `=IF(OR(Debt<-Tol,ABS(Debt-BS_Debt)>=Tol),1,0)` |
| Input ranges | Percentages sit between 0 and 100%, dates fall in order | `=IF(AND(Rate>=0,Rate<=1),0,1)` |
| Error scan | No cell in a range holds an Excel error value | `=IF(SUMPRODUCT(--ISERROR(Range))>0,1,0)` |
The error scan deserves a note. ISERROR returns TRUE for #REF!, #DIV/0!, #N/A, and the other error values. Wrapping it in SUMPRODUCT with the double negative turns the TRUE and FALSE values into 1 and 0 so they can be counted, and it works without array entry in current versions of Excel and in Google Sheets.
Making failures visible
A check that fails silently is nearly as bad as no check. Use three layers.
- Local flag. Put the check on its own row beneath the section it tests, with a clear label such as "Balance check (0 = OK)". Apply conditional formatting that fills the cell red when the value is 1. Leave it unformatted when the value is 0, so a passing model looks quiet.
- Master check. Add every check row into one total, so one number says whether anything failed anywhere.
- Cover sheet display. Show the master check where the user lands when opening the file. Add a text cell beside it, such as
=IF(C2=0,"OK","ERROR"), because a word is easier to notice than a number.
Following the fill-colour guidance from earlier in the tutorial, reserve red for failures and use it for nothing else.
Building checks with a script
The script below builds a small model with a deliberate imbalance of 0.5 in the third year. It adds a check row, red conditional formatting, a master check, and a status flag on a cover sheet. Run it, open checked_model.xlsx, and you will see the third check cell and the cover sheet flag turn red.
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill
from openpyxl.formatting.rule import CellIsRule
wb = Workbook()
ws = wb.active
ws.title = "Model"
ws["A1"] = "Balance sheet (millions)"
for col, year in zip("BCD", ["2025A", "2026F", "2027F"]):
ws[f"{col}1"] = year
ws["A2"] = "Total assets"
ws["A3"] = "Total liabilities and equity"
ws["A4"] = "Balance check (0 = OK)"
assets = [1000, 1100, 1210]
liab_eq = [1000, 1100, 1209.5] # 2027F is out by 0.5 on purpose
for col, a, le in zip("BCD", assets, liab_eq):
ws[f"{col}2"] = a
ws[f"{col}2"].font = Font(color="0000FF")
ws[f"{col}3"] = le
ws[f"{col}3"].font = Font(color="0000FF")
ws[f"{col}4"] = f"=IF(ABS({col}2-{col}3)<0.001,0,1)"
red = PatternFill(start_color="FFC7CE", end_color="FFC7CE", fill_type="solid")
ws.conditional_formatting.add(
"B4:D4", CellIsRule(operator="equal", formula=["1"], fill=red)
)
cover = wb.create_sheet("Cover", 0)
cover["B2"] = "Model checks (0 = all pass)"
cover["C2"] = "=SUM(Model!B4:D4)"
cover["D2"] = '=IF(C2=0,"OK","ERROR")'
cover.conditional_formatting.add(
"C2:D2", CellIsRule(operator="greaterThan", formula=["0"], fill=red)
)
wb.save("checked_model.xlsx")The D2 text flag does not turn red when the total is above zero, because the rule compares the cell's own value. For D2 the value is the word "ERROR", and text compared with a number does not behave as intended. If you want the word to change colour, add a separate rule with operator="equal" and formula=['"ERROR"'] on that cell.
Checks versus error flags
People use "check" and "flag" for different things, and it helps to keep them apart.
- A check tests a relationship that must hold, and its result feeds the master check.
- A flag marks a condition that a user should know about but that is not necessarily an error. Examples are a covenant ratio close to its limit, a forecast period that still uses a placeholder assumption, or a switch that is set to a non-default scenario.
Flags can use a different colour, such as amber, and should not add into the master check. If they did, the master check would stop meaning "the model is broken" and users would learn to ignore it.
Common errors
- Hiding errors with
IFERROR. Wrapping a calculation inIFERROR(formula,0)turns a#REF!into a plausible zero and removes the signal that a check should catch. UseIFERRORonly where the error is expected and you have decided what the fallback should be, and say why in a note. - A check that cannot fail. If the balance sheet's cash line is a plug that forces assets to equal liabilities plus equity, the balance check always passes. Test by changing an input in a way that should break the check, such as hardcoding over a formula, and confirm the check turns red. Then undo the change.
- A tolerance that is too loose. A tolerance of 1 in a model in millions allows errors of one million. Compare the tolerance with the units stated in the header.
- Checks on only some periods. A check row that stops at the last historical column leaves the forecast untested. Fill the check across the whole timeline.
- A master check that misses new rows. When someone inserts a check row outside the summed range, the master check ignores it. Put all checks in one block, or sum a range that spans every check row and keep the rows contiguous.
- Manual overrides left in place. A user hardcodes a number to force a check to pass. Pair the checks with the auditing steps covered later in this tutorial so that hardcodes inside formula rows are found.
Summary
A good check system follows a short list of rules: every check returns 0 for pass and 1 for fail, it uses ABS and a stated tolerance, it sits in a labelled row beneath what it tests, and it fills red only on failure. All checks roll up into a master check that appears on the cover sheet. Flags for non-error conditions use a different colour and stay out of the master total.
Exercise
A model is in thousands. A colleague writes the check =IF(D40-D55<1,0,1) for the balance sheet and reports that it passes in every period. Give two reasons this check is unreliable and write a corrected version, assuming the tolerance sits in a cell named Tol.
Show answer
First, there is no ABS. If liabilities and equity exceed assets, D40-D55 is negative and so is always below 1, so the check passes even when the sheet is badly out of balance. Second, the tolerance of 1 is hardcoded into the formula, and in a model in thousands it allows an error of 1,000 currency units, which is large compared with normal rounding. The corrected version is =IF(ABS(D40-D55)<Tol,0,1), with Tol held in one input cell (blue font) and set to a value such as 0.001.
Exercise
Your master check on the cover sheet shows 0, but a reviewer finds the cash flow statement's closing cash differs from balance sheet cash in 2028F. Name two possible explanations related to how the checks were built.
Show answer
Either no cash reconciliation check exists, so the model never tested this relationship, or the check exists but sits outside the range the master check sums (for example, the row was inserted below the summed block). Other valid answers are that the check row stops before the 2028F column, or that the check compares a plugged cash figure with itself and so cannot fail.