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.

Beginner 17 min read

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:

MenuExamples
Highlight Cells RulesGreater Than, Less Than, Between, Equal To, Text that Contains, A Date Occurring, Duplicate Values
Top/Bottom RulesTop 10 Items, Top 10%, Bottom 10 Items, Above Average, Below Average
Data BarsA bar inside each cell, proportional to its value
Color ScalesA colour gradient, for example green for high and red for low
Icon SetsArrows, traffic lights, ratings

Example: highlight large invoices

ABCDE
1InvoiceCustomerAmountDue dateStatus
2INV-301Alpha Ltd12002026-02-10Paid
3INV-302Beta GmbH8602026-02-20Open
4INV-303Gamma SA24502026-03-05Open
5INV-304Delta Inc3102026-03-18Paid
6INV-305Epsilon AB19752026-03-25Open

An invoice list. The lesson uses 2026-03-20 as 'today'.

  1. Select the amounts, C2:C6.
  2. Choose Home › Conditional Formatting › Highlight Cells Rules › Greater Than.
  3. Type 1500 (or click a cell containing the threshold, which makes the rule adjustable).
  4. Pick Light Red Fill with Dark Red Text or Custom Format and click OK.
  5. 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.
Watch out. By default, data bars, scales and icons compare each value to the minimum and maximum in the range. If all values are close together, tiny differences look huge. Set fixed minimum and maximum values in Edit Rule when the scale has a real meaning, such as 0% to 100%.

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

  1. Select the data rows A2:E6 (not the headers). Make sure A2 is the active cell (it stays white in the selection).
  2. Choose Home › Conditional Formatting › New Rule › Use a formula to determine which cells to format.
  3. Type the formula =AND($E2="Open", $D2<TODAY()).
  4. Click Format, choose a light red fill on the Fill tab, and click OK twice.
Formula
=AND($E2="Open", $D2<TODAY())
Written for row 2. The $ locks the columns; the row number stays relative so each row tests itself.

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.

Tip. Test a formula rule before using it: type the same formula into an empty column next to the data, fill it down, and check that TRUE appears exactly where you expect. Then copy it into the rule.

More formula rule ideas

GoalFormula (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.
Watch out. Copying and pasting cells, or inserting rows in the middle, can split one rule into many fragmented rules with odd ranges. If a sheet becomes slow, open Manage Rules, delete the fragments and re-create one rule for the whole range. Formatting data as a table reduces the problem.

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).
Note. All features in this lesson work in Excel 2016 and later on Windows and Mac. Excel for the web supports creating and editing most rule types, including formula rules, in current versions.

Check yourself

1. You select A2:E6 and create the formula rule =$E2="Open". What is formatted?

2. What would =$E$2="Open" do in the same rule?

3. Which formula shades every other row?

4. Two rules apply to the same cell and both set a fill colour. Which fill is shown?

5. Icon sets show three arrows based on…