Sub topic 10
Highlighting Dates and Deadlines
This chapter assumes you can write a formula-based rule, you know how the Applies to range works, and you can tell relative, absolute and mixed references apart. Date rules are formula rules that compare a date cell with today's date.
How Excel stores dates
Excel stores a date as a serial number. 1 January 1900 is 1, and each day adds 1. A date is therefore a number, so you can compare it with <, > and =, and you can add or subtract days.
TODAY() returns the current date and recalculates whenever the workbook recalculates. A rule that uses it updates itself each day without any editing.
The built-in date rule
Select the dates, then choose Home > Conditional Formatting > Highlight Cells Rules > A Date Occurring. The dialog offers fixed choices such as Yesterday, Today, Tomorrow, In the last 7 days, Last week, This week, Next week and This month.
This rule is quick, but it cannot combine conditions or look at other columns. For anything more specific, use a formula.
Formula rules for deadlines
Select the whole table, for example A2:E50, with the active cell at A2. Then choose New Rule > Use a formula to determine which cells to format. Lock the column with $ so the whole row is tested.
To highlight overdue tasks that are not finished, where column D holds the due date and column E holds the status:
=AND($D2<TODAY(), $E2<>"Done")To highlight tasks due in the next seven days, including today:
=AND($D2>=TODAY(), $D2<=TODAY()+7, $E2<>"Done")To highlight dates that fall on a weekend, with WEEKDAY set to return 1 for Monday and 7 for Sunday:
=WEEKDAY($D2,2)>5Give each rule its own fill color, for example red for overdue and amber for due soon. The Rules Manager chapter covers how ordering decides what you see when two rules apply.
Common errors
- Blank cells turn red. An empty cell counts as 0, which is earlier than today. Add a blank test:
=AND($D2<>"", $D2<TODAY(), $E2<>"Done"). - Nothing highlights. The dates may be text, often because they were imported or typed with an apostrophe. Check whether they are left-aligned, or test with
=ISNUMBER(D2). Convert them with Data > Text to Columns orDATEVALUE. - The wrong rows highlight. Check the reference style.
$D2locks the column and lets the row move.$D$2makes every row test the same cell. - Today's items show as overdue. The cell probably holds a date and a time, such as one entered with
NOW()orCtrl+;followed by a time. Compare withINT($D2)<TODAY()to ignore the time. - Results look stale.
TODAY()updates only when the workbook recalculates. If calculation is set to Manual, pressF9.
Putting it together
A typical task tracker uses three rules on $A$2:$E$50, in this order:
- Status is Done: gray font, with Stop If True checked.
- Due date before today: red fill.
- Due date within 7 days: amber fill.
Putting the Done rule first keeps finished tasks from being flagged as overdue, even if you leave out the $E2<>"Done" test in the later rules.
Exercise
A table in A2:D40 has due dates in column C. You want the entire row shaded red when the due date is in the past, but rows with an empty due date must stay unshaded. Write the rule formula and say which cell should be active when you create it.
Show answer
Select A2:D40 with A2 as the active cell, then use the formula =AND($C2<>"", $C2<TODAY()). The $ before C locks the column so every cell in the row tests column C. The row number stays relative so each row tests its own due date. The $C2<>"" test stops empty cells from being treated as 0 and highlighted.