Excel course · Lesson 11 of 34
Conditional formatting, including formula-based rules
Highlight values automatically: built-in rules, data bars, colour scales, icon sets and formula rules that colour whole rows, plus managing rule order.
Conditional formatting changes how a cell looks based on its value or on a formula. Unlike manual colouring, it reacts when data changes: an invoice turns red the day it becomes overdue and goes back to normal when it is paid. Used well, it guides the eye to what matters. Used badly, it turns a sheet into a rainbow nobody can read. This lesson goes from one-click rules to custom formula rules that highlight entire rows.
Quick rules
All conditional formatting starts at Home › Styles › Conditional Formatting. The menu has five families:
| Menu | Examples |
|---|---|
| Highlight Cells Rules | Greater Than, Less Than, Between, Equal To, Text that Contains, A Date Occurring, Duplicate Values |
| Top/Bottom Rules | Top 10 Items, Top 10%, Bottom 10 Items, Above Average, Below Average |
| Data Bars | A bar inside each cell, proportional to its value |
| Color Scales | A colour gradient, for example green for high and red for low |
| Icon Sets | Arrows, traffic lights, ratings |
Example: highlight large invoices
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Invoice | Customer | Amount | Due date | Status |
| 2 | INV-301 | Alpha Ltd | 1200 | 2026-02-10 | Paid |
| 3 | INV-302 | Beta GmbH | 860 | 2026-02-20 | Open |
| 4 | INV-303 | Gamma SA | 2450 | 2026-03-05 | Open |
| 5 | INV-304 | Delta Inc | 310 | 2026-03-18 | Paid |
| 6 | INV-305 | Epsilon AB | 1975 | 2026-03-25 | Open |
An invoice list. The lesson uses 2026-03-20 as 'today'.
- Select the amounts,
C2:C6. - Choose Home › Conditional Formatting › Highlight Cells Rules › Greater Than.
- Type
1500(or click a cell containing the threshold, which makes the rule adjustable). - Pick Light Red Fill with Dark Red Text or Custom Format and click OK.
- INV-303 (2,450) and INV-305 (1,975) are highlighted. Change C2 to 1,600 and it lights up immediately.
Data bars, colour scales and icon sets
These three visual rules show the size of a number relative to the others in the range, which turns a column of numbers into a mini chart.
- Data bars: best for amounts that are all positive, such as sales by rep. Choose Home › Conditional Formatting › Data Bars › Gradient Fill. To show bars without numbers, go to Manage Rules › Edit Rule and tick Show Bar Only.
- Colour scales: best for heat maps, such as monthly sales by region, or exam scores. A three-colour scale highlights the middle as well as the extremes.
- Icon sets: best for status at a glance. By default they split values by percentage of the range (top third, middle, bottom). For meaningful thresholds edit the rule and change Type from Percent to Number, for example green ≥ 90, yellow ≥ 70, red otherwise.
Formula-based rules
The most powerful option is Use a formula to determine which cells to format. You write a formula that returns TRUE or FALSE; where it is TRUE, the format is applied. The key to getting it right is understanding that the formula is written for the top-left cell of the selection, and Excel adjusts relative references for every other cell, exactly as if you had copied the formula.
Highlight the whole row of open, overdue invoices
- Select the data rows
A2:E6(not the headers). Make sureA2is the active cell (it stays white in the selection). - Choose Home › Conditional Formatting › New Rule › Use a formula to determine which cells to format.
- Type the formula
=AND($E2="Open", $D2<TODAY()). - Click Format, choose a light red fill on the Fill tab, and click OK twice.
=AND($E2="Open", $D2<TODAY())On 2026-03-20, INV-302 (due 2026-02-20, Open) and INV-303 (due 2026-03-05, Open) are highlighted across all five columns. INV-301 is overdue but Paid, so it stays normal. INV-305 is open but not yet due.
Why the dollar signs? Every cell in the row must look at column E and column D, so the columns are locked. But each row must look at its own row, so the row number is left relative. If you wrote $E$2, every row would follow the status of row 2. If you wrote E2, cell B2 would check F2 and C2 would check G2.
More formula rule ideas
| Goal | Formula (selection starts in row 2) |
|---|---|
| Shade every other row | =MOD(ROW(),2)=0 |
| Highlight weekends in a date column A | =WEEKDAY($A2,2)>5 |
| Highlight the row of the selected employee in H1 | =$A2=$H$1 |
| Flag values above the column average | =C2>AVERAGE($C$2:$C$6) |
| Flag duplicates of the invoice number | =COUNTIF($A$2:$A$6,$A2)>1 |
| Due within the next 7 days | =AND($D2>=TODAY(), $D2<=TODAY()+7) |
Managing rules
Home › Conditional Formatting › Manage Rules opens the Rules Manager. Set Show formatting rules for to This Worksheet to see everything on the sheet.
- Rules are evaluated top to bottom. Use the arrow buttons to change the order.
- If two rules apply to a cell and set different fill colours, the higher rule wins. Formats that do not conflict (one sets bold, the other a fill) are combined.
- Stop If True stops lower rules from applying when this rule is true (mainly useful with icon sets).
- Applies to shows the range. Extend it here rather than creating duplicate rules.
- Home › Conditional Formatting › Clear Rules removes rules from the selection or the whole sheet.
Good practice
- Highlight exceptions, not everything. Two or three colours per sheet is plenty.
- Put thresholds in cells (for example the 1,500 limit in
H2) and refer to them with$H$2, so users can change them without editing rules. - Do not rely on colour alone; colour-blind readers may miss red versus green. Icons or a text status column help.
- Conditional formatting cannot be used as a filter criterion directly, but you can sort and filter by the resulting colour (Filter by Color).
Check yourself
1. You select A2:E6 and create the formula rule =$E2="Open". What is formatted?
The locked column makes every cell in the row check E; the relative row lets each row check itself.
2. What would =$E$2="Open" do in the same rule?
With both parts locked, every cell tests E2.
3. Which formula shades every other row?
MOD(ROW(),2)=0 is TRUE on even rows.
4. Two rules apply to the same cell and both set a fill colour. Which fill is shown?
Rules are applied in list order and the higher rule wins when formats conflict.
5. Icon sets show three arrows based on…
Defaults use percent thresholds; edit the rule to use fixed numbers.