Sub topic 7
Common Patterns: Row Highlighting, Duplicates, and Overdue Dates
Assume you can select a range, open Format > Conditional formatting, and enter simple Google Sheets formulas. This chapter focuses on custom formula rules. A custom formula is a formula that returns TRUE or FALSE; Google Sheets applies the selected format when the result is TRUE.
Conditional formatting evaluates the formula separately for each cell in the rule's Apply to range. The formula's references therefore need to match the first row of that range.
Highlighting a Whole Row from One Cell
Suppose a task list uses this layout:
| A | B | C | D | E |
|---|---|---|---|---|
| Task | Owner | Status | Due date | Notes |
The data begins in row 2. To highlight every row whose status is Done:
- Select
A2:E100. - Open Format > Conditional formatting.
- For Format cells if, choose Custom formula is.
- Enter this formula:
=$C2="Done"- Choose a fill color and select Done.
The dollar sign before C locks the rule to column C. The row number has no dollar sign, so it changes as the rule evaluates rows 3, 4, and onward. For row 2, the rule checks C2. For row 8, it checks C8. Because the apply range covers columns A through E, the same status check formats the entire row.
A common mistake is writing =$C$2="Done". That checks only C2 for every row. If C2 contains Done, every row can be highlighted, even when its own status differs.
Marking Duplicate Values
To find repeated task names in column A:
- Select
A2:A100. - Choose Custom formula is.
- Enter:
=COUNTIF($A$2:$A$100,$A2)>1COUNTIF counts cells that match a criterion. The first reference, $A$2:$A$100, is fully anchored. Every row checks the same complete list. The second reference, $A2, keeps column A fixed but allows the row to change.
A value is highlighted when its count is greater than 1. This marks every occurrence of a duplicate, including the first occurrence. To mark only later occurrences, use a different pattern:
=COUNTIF($A$2:A2,$A2)>1Here, the counted range grows as the rule moves down the column. The first appearance has a count of 1. A later appearance has a count greater than 1.
Blank cells can also be treated as duplicates because empty cells may match one another. Exclude blanks when needed:
=AND($A2<>"",COUNTIF($A$2:$A$100,$A2)>1)Highlighting Overdue Work
For the task layout above, assume column D contains due dates and column E contains status values. To highlight tasks whose due date has passed and that are not complete:
- Select
A2:E100. - Choose Custom formula is.
- Enter:
=AND($D2<TODAY(),$E2<>"Done")TODAY() returns the current date. AND returns TRUE only when both conditions are true. The row is therefore highlighted when the due date is before today and the status is anything except Done.
This formula does not highlight a task due today. If “due today” should also count as overdue, use <= instead of <:
=AND($D2<=TODAY(),$E2<>"Done")If empty due-date cells are being highlighted, add a nonblank check:
=AND($D2<>"",$D2<TODAY(),$E2<>"Done")The due-date cells must contain real date values, not text that only looks like a date. You can test a cell by changing its format or using it in a date calculation.
Choosing Anchors
Use references according to what should stay fixed as the rule moves:
| Reference | Meaning when the rule moves |
|---|---|
| `C2` | Column and row can change |
| `$C2` | Column C stays fixed; row changes |
| `C$2` | Row 2 stays fixed; column changes |
| `$C$2` | Both column C and row 2 stay fixed |
For row highlighting, $C2 is usually the correct form. For duplicate detection, the full search range uses $A$2:$A$100, while the current value uses $A2.
Troubleshooting the Common Patterns
When a rule highlights the wrong rows, check these points:
- The formula's row number matches the first row of the apply range.
- The column that drives the rule has a dollar sign, such as
$C2. - The search range for
COUNTIFis fully anchored. - Dates are stored as dates, and the status text matches exactly.
- Blank values are excluded when they should not qualify.
- The rule applies to the intended range, such as
A2:E100rather than onlyA2:A100.
Exercise
Your data starts in row 3. Column C contains status values, and you want to highlight A3:F100 when the status is "Blocked". Which custom formula should you use?
Show answer
Use =$C3="Blocked". The column is fixed so every cell in the row checks column C, while the row changes for each record.