Confident CellsExcel practice Start free

Conditional formatting with a formula: colour a whole row

Updated 26 November 2026 · 6 min read

To colour cells with a formula, select them, go to Home › Conditional Formatting › New Rule, choose Use a formula to determine which cells to format, and type a formula that's TRUE for the cells to colour, such as =$D2="Overdue". Click Format, pick a fill, and click OK twice. It works the same way in Excel for Windows and Excel for Mac, where you change Style to Classic first.

Rules worth copying, at a glance

Each one is written for data starting in row 2. Select from row 2 down, across every column you want coloured, before you add it.

To colour the row whenRule
Status is Overdue=$D2="Overdue"
It's unpaid and £500 or more=AND($D2="Unpaid",$C2>=500)
Either of two things is true=OR($D2="Overdue",$C2>=1000)
The amount is over the target in G1=$C2>$G$1
The due date in E has passed=AND($E2<>"",$E2<TODAY())
The invoice number appears more than once=COUNTIF($A$2:$A$200,$A2)>1
The customer name contains "School"=ISNUMBER(SEARCH("School",$B2))
Every other row, for stripes=MOD(ROW(),2)=0

The AND and OR rules are explained in AND and OR, the duplicates rule in finding duplicates, and the SEARCH rule in if a cell contains text. G1 has $ on both parts, because every cell should compare with the same target. The sheets below work each kind through.

A worked example: colour every overdue row

An invoice list has a Status in column D. We want the whole row coloured, A to D, for every overdue invoice. A drop-down list on the Status column helps here: everyone picks the same word, spelled the same way, so the rule finds every one.

  1. Select A2:D7: every row of data, without the headings.
  2. The rule is =$D2="Overdue". For row 2, D2 says Paid, so the rule gives FALSE and row 2 stays white.
  3. For row 3, Excel checks =$D3="Overdue". D3 says Overdue, so it's TRUE and A3 to D3 are coloured.
ABCDE
1InvoiceCustomerAmountStatusRule gives
2INV-201Harper Ltd£820.00PaidFALSE
3INV-202Oak Cafe£500.00OverdueTRUE
4INV-203J Singh£240.00UnpaidFALSE
5INV-204Bell & Co£1,150.00OverdueTRUE
6INV-205Penn School£75.00PaidFALSE
7INV-206Oak Cafe£380.00UnpaidFALSE
Column E shows what the rule works out for each row. Rows 3 and 5 give TRUE, so those two rows are coloured.

Why the $ goes before D

Excel writes the rule for the top-left cell you selected, A2, and moves it for every other cell, just as if the formula were copied there.

Lock both, =$D$2="Overdue", and every row checks D2: the whole list is coloured or none of it is.

Compare with a target in one cell

A target of £1,000 sits in F1, and rows over it should be green. Asha's £1,200 is over £1,000, so her row is coloured. Ben's £800 isn't. The rule is =$B2>$F$1, with $ on both parts of F1 so every row compares with the same cell.

ABCDEF
1NameSalesWith $F$1Without $Target£1,000.00
2Asha£1,200.00TRUETRUE
3Ben£800.00FALSETRUE
4Cleo£1,500.00TRUETRUE
5Dan£950.00FALSETRUE
6Ema£1,050.00TRUETRUE
C2 holds =$B2>$F$1 and D2 holds =$B2>F1, both copied down. Without the $, row 3 compares with the empty cell under the target, so every row gives TRUE.

Without the $, the rule for row 3 looks at F2, which is empty. An empty cell counts as 0, and £800 is more than 0, so Ben's row is coloured too, and so is every row after it.

Dates: overdue, and due soon

With due dates in column B, =$B2<TODAY() colours every date before today. It also colours rows with no date yet, because an empty cell counts as 0, the earliest date there is. Add a check that the cell isn't empty: =AND($B2<>"",$B2<TODAY()). For "due in the next 7 days", the date must be today or later and no more than 7 days away.

ABCDE
1InvoiceDueBefore todayHas a date, and passedDue in 7 days
2INV-40102/03/2026TRUETRUEFALSE
3INV-40220/03/2026FALSEFALSETRUE
4INV-403TRUEFALSEFALSE
5INV-40431/03/2026FALSEFALSEFALSE
6INV-40516/03/2026FALSEFALSETRUE
7INV-40610/03/2026TRUETRUEFALSE
Worked out as if today were 16 March 2026. C2 holds =$B2<TODAY(), D2 holds =AND($B2<>"",$B2<TODAY()) and E2 holds =AND($B2>=TODAY(),$B2<=TODAY()+7). INV-403 has no date: column C says TRUE, column D doesn't.

INV-405 is due today, so it isn't overdue yet but it is due soon. Two rules on the same rows can colour them red and amber; see Change or remove a rule below for which one wins. TODAY() changes every day, so the colours move by themselves. There's more on dates in working days between two dates.

Duplicates: every copy, or only the repeats

COUNTIF counts how many times this row's invoice number appears in the whole list. More than 1 means it's a duplicate. To colour only the second and later copies, count from the top of the list down to this row: the range $A$2:$A2 grows by one row each time it moves down.

ABCD
1InvoiceAmountEvery copyRepeats only
2INV-501£820.00FALSEFALSE
3INV-502£500.00TRUEFALSE
4INV-503£240.00FALSEFALSE
5INV-502£500.00TRUETRUE
6INV-504£1,150.00FALSEFALSE
7INV-505£75.00FALSEFALSE
C2 holds =COUNTIF($A$2:$A$7,$A2)>1 and D2 holds =COUNTIF($A$2:$A2,$A2)>1, both copied down. INV-502 is in rows 3 and 5; only row 5 is a repeat.

For a list that will grow, make the range longer than you need, such as $A$2:$A$200. More ways to find and remove duplicates are in how to find duplicates in Excel.

On a Mac

Go to Home › Conditional Formatting › New Rule. The box opens on a colour scale, so change Style to Classic first. The option Use a formula to determine which cells to format is in the list below it. Type the formula, then set Format with to custom format to choose your own fill.

Test the rule in a cell first

A rule that doesn't work just colours nothing, with no error to tell you why. So type the formula in a spare column first, in the top row, and copy it down, as the sheets above do. Where it shows TRUE, the rule will colour. When it's right, copy it from the formula bar into the New Rule box and clear the spare column.

Change or remove a rule

Home › Conditional Formatting › Manage Rules lists the rules. Set Show formatting rules for to This Worksheet to see them all. Click a rule and Edit Rule to change the formula or the colour, or change Applies to to cover more rows. When two rules colour the same cell, the one higher in the list wins. To remove rules, select the cells and choose Conditional Formatting › Clear Rules › Clear Rules from Selected Cells.

Common mistakes

Every row is coloured, or none

The row is locked: =$D$2="Overdue". Take out the $ before the 2.

The colour is one row out

You selected from row 1, the headings, but wrote the rule for row 2. The rule must be for the first row you selected. Select from row 2, or write the rule for row 1.

Only part of the row is coloured

The column isn't locked: =D2="Overdue". Add the $ before D.

Rows with no date are coloured as overdue

An empty cell counts as 0, which is before any date. Add a check that it isn't empty: =AND($E2<>"",$E2<TODAY()).

Nothing is coloured at all

Check you chose Use a formula to determine which cells to format, the last option in the list, and that the formula starts with =. Without the =, Excel takes it as text and adds quotes round it. Text in the formula needs quotes of its own: "Overdue". A rule that gives words, such as =IF(…,"Yes","No"), never colours anything: it must give TRUE or FALSE.

Try it now

Your turn

Test a rule before you add it. The rule should colour every invoice that's Unpaid and for £500 or more. In E2, write the rule's formula so it gives TRUE for those rows. Your formula will be copied down to E9.

ABCDE
1InvoiceCustomerAmountStatusColour it?
2INV-301Harper Ltd£820.00Paid
3INV-302Oak Cafe£500.00Unpaid
4INV-303J Singh£240.00Unpaid
5INV-304Bell & Co£1,150.00Unpaid
6INV-305Oak Cafe£499.00Unpaid
7INV-306Harper Ltd£600.00Paid
8INV-307Penn School£75.00Unpaid
9INV-308J Singh£980.00Paid

Open this in Try a formula: the same sheet with the answer filled in, to change or share by link.

Part of Excel data analysis practice: every lesson on the topic, with a project in Excel.

Questions

How do I highlight a whole row based on one cell in Excel?

Select every row of data, from the first column to the last, without the headings. Go to Home › Conditional Formatting › New Rule, choose Use a formula to determine which cells to format, and type a rule for the first row with a $ before the column letter, such as =$D2="Overdue". The $ keeps every cell in the row looking at column D, so the whole row is coloured.

Why is my conditional formatting formula not working?

Usually it's the $ signs or the starting row. The rule must be written for the top-left cell you selected, with $ before the column and none before the row: =$D2. Check too that the formula starts with =, that text is in quotes, and that it gives TRUE or FALSE rather than words. Typing the rule in a spare column first shows what it gives on each row.

How do I highlight dates that have passed in Excel?

Use the rule =AND($E2<>"",$E2<TODAY()), with the dates in column E, starting at row 2. TODAY() is today's date, so anything before it has passed, and the colours change by themselves each day. The $E2<>"" part stops rows with no date being coloured, because an empty cell counts as 0, which is earlier than any date.

How do I copy conditional formatting to other cells?

Click a cell that has the rule, click Format Painter on the Home tab, then select the cells to copy it to. It's on the Home tab in Excel for Mac too. Or open Conditional Formatting › Manage Rules, pick the rule and change its Applies to box to cover more cells. Changing Applies to keeps one rule, which is easier to edit later.