Conditional formatting with a formula: colour a whole row
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 when | Rule |
|---|---|
| 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.
- Select A2:D7: every row of data, without the headings.
- The rule is
=$D2="Overdue". For row 2, D2 says Paid, so the rule gives FALSE and row 2 stays white. - For row 3, Excel checks
=$D3="Overdue". D3 says Overdue, so it's TRUE and A3 to D3 are coloured.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Invoice | Customer | Amount | Status | Rule gives |
| 2 | INV-201 | Harper Ltd | £820.00 | Paid | FALSE |
| 3 | INV-202 | Oak Cafe | £500.00 | Overdue | TRUE |
| 4 | INV-203 | J Singh | £240.00 | Unpaid | FALSE |
| 5 | INV-204 | Bell & Co | £1,150.00 | Overdue | TRUE |
| 6 | INV-205 | Penn School | £75.00 | Paid | FALSE |
| 7 | INV-206 | Oak Cafe | £380.00 | Unpaid | FALSE |
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.
- The $ before D stops the column moving, so B2, C2 and D2 all look at column D. Without it, B2 would check E2, the next column along, and the row would be coloured in patches.
- No $ before 2 lets the row move, so row 3 checks D3 and row 4 checks D4.
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.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Name | Sales | With $F$1 | Without $ | Target | £1,000.00 |
| 2 | Asha | £1,200.00 | TRUE | TRUE | ||
| 3 | Ben | £800.00 | FALSE | TRUE | ||
| 4 | Cleo | £1,500.00 | TRUE | TRUE | ||
| 5 | Dan | £950.00 | FALSE | TRUE | ||
| 6 | Ema | £1,050.00 | TRUE | 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.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Invoice | Due | Before today | Has a date, and passed | Due in 7 days |
| 2 | INV-401 | 02/03/2026 | TRUE | TRUE | FALSE |
| 3 | INV-402 | 20/03/2026 | FALSE | FALSE | TRUE |
| 4 | INV-403 | TRUE | FALSE | FALSE | |
| 5 | INV-404 | 31/03/2026 | FALSE | FALSE | FALSE |
| 6 | INV-405 | 16/03/2026 | FALSE | FALSE | TRUE |
| 7 | INV-406 | 10/03/2026 | TRUE | TRUE | FALSE |
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.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Invoice | Amount | Every copy | Repeats only |
| 2 | INV-501 | £820.00 | FALSE | FALSE |
| 3 | INV-502 | £500.00 | TRUE | FALSE |
| 4 | INV-503 | £240.00 | FALSE | FALSE |
| 5 | INV-502 | £500.00 | TRUE | TRUE |
| 6 | INV-504 | £1,150.00 | FALSE | FALSE |
| 7 | INV-505 | £75.00 | FALSE | FALSE |
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
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.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Invoice | Customer | Amount | Status | Colour it? |
| 2 | INV-301 | Harper Ltd | £820.00 | Paid | |
| 3 | INV-302 | Oak Cafe | £500.00 | Unpaid | |
| 4 | INV-303 | J Singh | £240.00 | Unpaid | |
| 5 | INV-304 | Bell & Co | £1,150.00 | Unpaid | |
| 6 | INV-305 | Oak Cafe | £499.00 | Unpaid | |
| 7 | INV-306 | Harper Ltd | £600.00 | Paid | |
| 8 | INV-307 | Penn School | £75.00 | Unpaid | |
| 9 | INV-308 | J Singh | £980.00 | Paid |
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.