Skip to content

Highlight whole rows with a formula rule

Conditional formatting9 minPremium

Builds on Highlight cells with conditional formatting, Fill a table with mixed references, Combine tests with AND, OR and NOT and Build dates with DATE, and use TODAY and NOW.

A fleet manager in Cork keeps the service dates of 40 company vans in one list. Each month she sets a report date, and every van due for a service before it should show as a colored row, from the registration to the date, so none slips past when she scrolls.

How it works

The ready-made rules test the cell they color. To color a whole row because of one of its cells, or to test anything the menus don't offer, write the test yourself: Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format. On a Mac, choose Classic in the Style box first.

The formula is a test that returns TRUE or FALSE, the kind you'd put inside IF, and it starts with =. Excel reads it as written for the active cell, the first cell of your selection, and moves it to every other cell the way a copied formula moves. With the vans in A2:B7 and the report date in B9, the rule for the rows is:

=$B2<$B$9
Tests whether the service date in column B of each row is earlier than the report date in B9.

$B keeps every cell of a row on column B, so the whole row lights up together, and the row number moves with each row. $B$9 keeps every row on the report date. Type the same test in a spare column and fill it down, and you see what the rule sees:

The rule runs the same test on every row. Rows 2, 5 and 7 come out TRUE, so a rule on A2:B7 colors them. The van due on 30 Nov 2026 isn't before the report date. In C4, =$B4<$B$9 returns FALSE. Test in C: C2 =$B2<$B$9, C3 =$B3<$B$9, C4 =$B4<$B$9, C5 =$B5<$B$9, C6 =$B6<$B$9, C7 =$B7<$B$9.

The $ signs decide which cells each copy of the rule reads:

In cell=$B2<$B$9 becomes=B2<$B$9 becomes=$B$2<$B$9 becomes
A2=$B2<$B$9=B2<$B$9=$B$2<$B$9
B2=$B2<$B$9=C2<$B$9=$B$2<$B$9
A3=$B3<$B$9=B3<$B$9=$B$2<$B$9
B3=$B3<$B$9=C3<$B$9=$B$2<$B$9
$B2 keeps every cell of a row on column B of that row. Without the $, the cells in column B test column C. With $B$2, every row tests row 2.

Common mistakes

  • =B2<$B$9 without the $ before B. The cells in column B test column C instead, so only column A comes out right.
  • =$B$2<$B$9 tests row 2 from every row, so the whole range is colored or none of it. Clicking a cell while you type the rule inserts this fully locked form: delete the $ before the row number.
  • A formula written for another row. If the selection starts in row 4, the formula must say $B4.
  • < and <= give different answers on the report date itself. Decide what overdue means on that day before you write the test.

In short

  • A formula rule is a TRUE or FALSE test, written for the first cell of the selection.
  • To color whole rows, lock the column of the cell you test and leave the row free, as in $B2.
  • Lock both parts of a cell that every row compares with, such as a report date or a limit: $B$9.

Practice

Premium

4 exercises: 1 formula and 3 conditional formats.

Practice is part of Premium

Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.