Sub topic 11
Troubleshooting rules that do not behave as expected
This chapter assumes you can open the conditional formatting sidebar, select a range such as A2:F100, and write a custom formula rule using $ anchors. If a rule highlights the wrong cells, highlights nothing, or reports an error, the cause is almost always one of a small set of problems. This chapter gives you a fixed order for checking them.
A method for diagnosing a rule
Guessing at fixes is slow. A rule has three parts: the range it applies to, the condition it evaluates, and the format it applies. It also competes with other rules. Check them in this order:
- Is the rule enabled and does its range cover the cell?
- Does the condition evaluate to TRUE for that cell?
- Does a rule above it already format the cell?
- Is something else, such as manual formatting, hiding the result?
Step 1: Confirm the range
Open the rule by clicking any cell it should affect, then read the Apply to range box. Three range problems are common.
- The range stops short. You added rows below row 100, but the rule still covers A2:F100. Extend the range, or apply the rule to a larger one such as A2:F1000.
- The range includes the header. If the range starts at A1 but your formula refers to row 2, the formula is offset by one row. Step 3 explains why.
- The range is fragmented. Copying and pasting cells, inserting rows, or pasting only formatting can split one rule into several rules with narrow ranges. You then see many rules in the sidebar that each cover a few cells. Delete the fragments and recreate a single rule over the whole range.
If a rule in the sidebar shows no sign of firing, check for a rule that sits on the correct sheet tab. Rules belong to one sheet, so a rule created on Sheet1 never affects Sheet2.
Step 2: Check what the condition actually sees
A rule formats a cell only when its condition is TRUE for the value the cell holds. The value displayed on screen may differ from the underlying value.
Numbers and dates stored as text
A value pasted from another system may look like a number but be text. Text is usually left-aligned by default, while numbers are right-aligned. Comparisons such as $B2>100 do not behave numerically when B2 holds the text "150". Dates have the same problem: a "date" typed as text cannot be compared with TODAY().
To test a cell, enter this in an empty helper cell:
=ISNUMBER(B2)If it returns FALSE, convert the column. For text numbers, =VALUE(B2) in a helper column, or Format > Number, then re-entering the values, usually works. Once the data is clean, your rule can stay simple.
Trailing spaces and case
An exact match fails when a cell contains "Done " with a trailing space. The rule =$C2="Done" is not TRUE for that cell, even though it looks identical. Comparison with = ignores letter case, so "done" and "DONE" both match. If spaces are the issue, wrap the reference in TRIM:
=TRIM($C2)="Done"Blank cells
Blank cells are a frequent source of unexpected highlighting. In a numeric or date comparison, a blank cell counts as 0. The overdue rule from earlier chapters, =AND($D2<TODAY(),$E2<>"Done"), therefore highlights every empty row, because a blank D2 counts as a date long before today and a blank E2 is not "Done". Add an explicit check:
=AND($D2<>"",$D2<TODAY(),$E2<>"Done")Built-in conditions such as Less than can show the same behavior with empty cells. If empty cells light up, switch to a custom formula that excludes them, for example =AND($B2<>"",$B2<50).
Step 3: Check anchors and the starting row
A custom formula is written from the point of view of the top-left cell of the range. Sheets then adjusts the references for every other cell, following the $ anchors. If the formula refers to the wrong row for that top-left cell, every cell evaluates the wrong neighbor.
Suppose the rule applies to A2:F100. The top-left cell is A2, so the formula should refer to row 2:
=$C2="Done"Compare three mistaken versions:
| Formula | Applied to A2:F100 | What goes wrong |
|---|---|---|
| `=$C1="Done"` | Each row checks the status in the row above | Highlight appears one row too low |
| `=C2="Done"` | Column shifts as the rule moves right | In column B the rule checks D, in column C it checks E, and so on |
| `=$C$2="Done"` | Every cell checks only C2 | Either the whole range highlights or nothing does |
The pattern is fixed. Anchor the column with $ when you want every cell in a row to look at the same column. Leave the row relative so it changes from row to row. Anchor both when you compare against a single fixed cell, such as a threshold in $H$1.
If the rule is applied to a range starting at A1 and you wrote $C2, then A1 evaluates C2. The header row is checked against row 2, and every row is one off. To fix it, make the starting row of the range and the row in the formula agree.
Test the formula in a helper cell
You can see what the rule sees by reproducing the formula in a normal cell. Put the same formula, written for the top-left cell, in a spare column in row 2, then fill it down. The column shows TRUE or FALSE for each row, which tells you whether the condition or something else is at fault. For example, in column H, row 2:
=AND($D2<>"",$D2<TODAY(),$E2<>"Done")If the helper column shows TRUE where you expect highlighting, the condition is right and the problem lies in the range, the rule order, or the format. If it shows FALSE, fix the formula. Delete the helper column when you are done.
Step 4: Check rule order and competing formats
Sheets evaluates rules from the top of the list. For a cell that matches several rules, the first matching rule in the list wins for any property they both set, such as fill color. If a general rule sits above a specific one, the specific one never shows.
Open the sidebar, drag the rules into the order you want, and put the most specific rule first. A rule that sets only text color and one that sets only fill color can both apply to the same cell, because they set different properties. Two rules that both set a fill color cannot.
Two further conflicts are easy to miss:
- Manual formatting. A fill color you applied by hand is overridden when a rule formats the same property. That is expected. If the rule does not fire and you see an old color, the color may have come from manual formatting, so clear it with Format > Clear formatting on a copy first.
- Alternating colors. The Format > Alternating colors feature is separate from conditional formatting. A conditional rule paints over it, but a rule that does not match leaves the banding visible and can look like a stray color.
Step 5: Troubleshoot specific formulas
Duplicates
The rule =COUNTIF($A$2:$A$100,$A2)>1 marks every copy, including the first one. It also marks nothing if the list contains near-duplicates such as "Smith" and "Smith ". Apply TRIM to the data, not to the rule. Remember that COUNTIF ignores case, so "abc" and "ABC" count as duplicates. If you add rows below row 100, extend both the applied range and the counted range in the formula, or the new rows are ignored.
Dates and `TODAY()`
TODAY() recalculates when the spreadsheet recalculates, so an overdue highlight can change at midnight or when you reopen the file. A rule comparing to TODAY() does not use the time zone you expect if the spreadsheet's time zone is set differently. Check File > Settings if dates flip a day early or late.
Alternating rows
=MOD(ROW(),2)=0 shades even sheet rows. If your table starts on row 2 and you want row 2 shaded, use =MOD(ROW(),2)=0. If you want the first data row unshaded, use =MOD(ROW(),2)=1. The row number is the sheet row, not the position within the range.
Other sheets and INDIRECT
A custom formula rule cannot refer to another sheet directly. Wrap the reference in INDIRECT and pass it text:
=COUNTIF(INDIRECT("Lists!A:A"),$A2)>0Common failures are:
- A wrong sheet name. The text must match the tab name exactly. If the name contains spaces or punctuation, put single quotes inside the double quotes:
INDIRECT("'Lists 2024'!A:A"). - A renamed tab.
INDIRECTtakes text, so Sheets does not update it when you rename the tab. The rule then quietly stops matching. - A missing quote. The sheet reference must be a string.
INDIRECT(Lists!A:A)without quotes is read as a direct reference and is rejected.
Invalid formula messages
The sidebar shows Invalid formula under the box when the expression cannot be parsed. Look for unmatched parentheses, a missing = at the start, a list separator that does not match your locale (some locales use ; instead of ,), or straight quotes replaced by curly quotes after pasting from a document. Retype the quotes in the formula box if you copied the formula from elsewhere.
Quick reference
| Symptom | Likely cause | Fix |
|---|---|---|
| Nothing highlights | Range does not include the cell, or the rule is on another sheet | Check Apply to range and the sheet tab |
| Highlight is one row off | Formula refers to a different row than the range start | Align the formula row with the first row of the range |
| Only some columns work | Column not anchored | Use `$C2` instead of `C2` |
| Whole range highlights | Row anchored too, as in `$C$2` | Remove the `$` before the row number |
| Empty rows highlight | Blank cells count as 0 in comparisons | Add `$D2<>""` to the formula |
| Text matches fail | Trailing spaces or text stored as numbers | Use `TRIM`, `VALUE`, or clean the data |
| Specific rule never shows | A broader rule is above it | Drag the specific rule to the top |
| Many tiny rules in the list | Copy and paste fragmented the range | Delete them and recreate one rule |
| Cross-sheet rule fails | Sheet name wrong or reference not in quotes | Wrap the reference in `INDIRECT("...")` with exact name |
Exercise
A rule applies to A2:F100 with the formula =$C1="Done". Rows with "Done" in column C are not highlighted. The row below each one is highlighted instead. What is wrong, and what formula fixes it?
Show answer
The formula refers to row 1, but the range starts at row 2, so every cell checks the status in the row above it. Change the formula to =$C2="Done" so the top-left cell A2 checks C2 and every other cell follows with the column anchored and the row relative.
Exercise
The rule =AND($D2<TODAY(),$E2<>"Done") highlights rows 40 to 100, which are completely empty. Why does this happen, and how do you stop it?
Show answer
A blank date in D counts as 0, which is earlier than today, and a blank status in E is not "Done", so both conditions are TRUE. Add a check that the date is present: =AND($D2<>"",$D2<TODAY(),$E2<>"Done").
Exercise
A cross-sheet rule =COUNTIF(INDIRECT("Lists!A:A"),$A2)>0 stopped matching after a colleague renamed the tab to "Lists 2024". What should the formula be?
Show answer
=COUNTIF(INDIRECT("'Lists 2024'!A:A"),$A2)>0. INDIRECT takes text, so Sheets does not update it when the tab is renamed. The new name contains a space, so it needs single quotes inside the double quotes.