Tabellab
Excel formulas

Conditional formatting formula examples in Excel

A conditional formatting formula is a TRUE/FALSE test written for the top-left cell of the range you format. Excel copies it to every other cell the way it copies a normal formula, and colours the cells where it returns TRUE. Most rules you will ever need are one of a handful of patterns. To highlight a whole row when an invoice is open and past due, apply =AND($E2="Open",$C2<$C$13) to A2:F11. The dollar signs before the column letters are the whole trick. In the example below that rule catches 3 overdue invoices worth $6,525.50, and the guide adds nine more conditional formatting formula examples you can copy.

Updated 21 Oct 2026 6 min read By Tabellab team

Where the formula goes

Select the range, for example A2:F11, then Home › Conditional Formatting › New Rule › Use a formula to determine which cells to format. Type the formula, click Format, pick a fill and confirm. In Google Sheets the same option is Format › Conditional formatting › Custom formula is.

The formula must return TRUE or FALSE (any non-zero number also counts as TRUE). Write it as if it sat in the first cell of the selection, A2 here. Excel then shifts every relative reference for the other cells, exactly as if you had copied the formula down and across.

The $ rule: lock the column, not the row

To colour a full row from one column, lock the column with $ and leave the row free: $E2. Every cell in row 2, from A2 to F2, then looks at E2, and every cell in row 3 looks at E3. Without the dollar sign, B2 would test F2 and C2 would test G2, and the colours land in the wrong places.

Fixed inputs such as the as-of date get two dollar signs, $C$13, so every cell compares with the same date. This is the same absolute-reference logic as in a SUMIFS criteria cell. If a rule colours one row too low or one cell too far right, the references are almost always written for the wrong starting cell.

Ten conditional formatting formula examples

All examples are written for a range starting in row 2, with invoices in A2:F11 as in the sheet below.

  • Overdue and still open (whole row): =AND($E2="Open",$C2<$C$13). Use TODAY() instead of $C$13 for a rule that updates every day.
  • Due in the next 7 days: =AND($E2="Open",$C2>=$C$13,$C2<=$C$13+7)
  • Top 3 amounts: =$D2>=LARGE($D$2:$D$11,3)
  • Below average: =$D2<AVERAGE($D$2:$D$11)
  • Duplicate customer: =COUNTIF($B$2:$B$11,$B2)>1
  • Second and later occurrence only: =COUNTIF($B$2:$B2,$B2)>1 (the range grows down the list)
  • Banded rows: =MOD(ROW(),2)=0, which survives sorting and inserted rows
  • Weekend dates: =WEEKDAY($C2,2)>5
  • Blank required field: =$D2=""
  • Text contains a word: =ISNUMBER(SEARCH("hotel",$B2)), not case-sensitive

Test the rule in a helper column first

A rule that colours nothing gives no error message. The fastest way to debug it is to type the same formula into a spare column next to the data and copy it down: you see TRUE or FALSE per row and can fix the logic before it goes into the rule box. Column F of the example does this. Multiplying by 1, =AND(…)*1, turns TRUE and FALSE into 1 and 0, so you can also count and sum the results: 3 overdue invoices, and =SUMPRODUCT(D2:D11,F2:F11) = $6,525.50 overdue. When the column is right, paste the formula without *1 into the rule and delete the helper, or keep it hidden as documentation.

Note the boundary in the overdue rule. INV-405 is due on the as-of date itself, 15 Oct 2026, and is not late yet, so the rule uses <, not <=. Paid invoices never turn red because AND needs both conditions.

Worked example: helper column for an overdue-invoice rule

Column F holds the overdue rule as a formula, times 1 so the result shows as 1 or 0. Rows 14 to 19 count what the other example rules would colour. The invoices are fictional.

Worked example: helper column for an overdue-invoice rule
ABCDEF
1InvoiceCustomerDue dateAmountStatusOverdue rule (1 = TRUE)
2INV-401Harbor Cafe28 Sep 20261,240.00Paid0
3INV-402Lumen Hotel02 Oct 20263,860.00Open1
4INV-403Pier 4 Deli09 Oct 2026515.50Open1
5INV-404Cityline Offices14 Oct 20262,150.00Open1
6INV-405Lumen Hotel15 Oct 20263,860.00Open0
7INV-406Northpark Gym18 Oct 2026780.00Open0
8INV-407Harbor Cafe20 Oct 20261,240.00Paid0
9INV-408Oak & Ivy Bistro01 Oct 2026960.00Paid0
10INV-409Fernwood College21 Oct 20264,420.00Open0
11INV-410Pier 4 Deli30 Oct 2026515.50Open0
12
13As of15 Oct 2026
14Overdue invoices3
15Overdue amount6,525.50
16Top 3 cut-off: 3rd largest amount3,860.00
17Average amount (below-average rule)1,954.10
18Rows with a repeated customer6
19Open and due in the next 7 days3
Key formulas
  • F2=AND($E2="Open",$C2<$C$13)*1Overdue rule, paste it without *1 into the rule box
  • F15=SUMPRODUCT(D2:D11,F2:F11)Amount the rule colours
  • F16=LARGE(D2:D11,3)Top 3 rule cut-off
  • F18=SUMPRODUCT(--(COUNTIF(B2:B11,B2:B11)>1))Rows the duplicate rule colours

In the rule box, write references for the first cell of the range you selected (row 2 here). The as-of date in C13 can be replaced with TODAY().

Several rules on one range: order and Stop If True

When rules overlap, open Conditional Formatting › Manage Rules. Rules higher in the list win when they set the same property, for example both a red and an amber fill. Put the most severe rule on top, or tick Stop If True so that a cell that matched stays out of the rules below. For a clean red, amber, green status it is often easier to calculate the status with IFS in a column and colour that column with three simple equal to rules.

Formula rules vs built-in rules

The built-in rules, such as Top 10, Above Average or Duplicate Values, colour only the cells of the column you selected. A formula rule can colour the whole row, combine conditions with AND and OR and use any other column. In the example, the built-in Top 10 rule set to 3 items would colour the same three amounts as the LARGE formula, $4,420.00 and the two invoices of $3,860.00, but only the formula version can paint the full invoice line.

Common mistakes

  • Writing the formula for the wrong cell. The formula is relative to the top-left cell of the selected range. If you select A2:F11 but write the rule for row 1, every colour is shifted by one row.
  • No $ before the column. =E2="Open" applied to a whole row makes each cell test a different column. Use $E2.
  • Locking the row as well. $E$2 makes every row test the first invoice, so the whole table is coloured or nothing is.
  • Comparing with text that looks like a date. $C2<"15/10/2026" compares with text. Put the date in a cell or use DATE(2026,10,15) or TODAY().
  • Leaving out the = sign. Without it, Excel stores the entry as text in quotes and the rule never fires. Start every rule with = and check it in Manage Rules.
  • Piling up copies of the same rule. Copying and pasting cells duplicates rules for each pasted range. Clean them up in Manage Rules so one rule covers the whole range.

Frequently asked questions

How do I use a formula in conditional formatting?

Select the range, choose Home, Conditional Formatting, New Rule, Use a formula to determine which cells to format, type a formula that returns TRUE or FALSE for the top-left cell of the range, set a format and click OK.

How do I highlight an entire row based on one cell?

Select all the columns of the table, starting in the first data row, and use a formula that locks the column of the test cell, for example =$E2="Open". The $ keeps every cell of the row pointing at column E.

Why is my conditional formatting formula not working?

Usually the references are written for the wrong starting cell, the column is not locked with $, or a date or number is compared with text. Test the formula in a helper column first to see TRUE or FALSE for each row.

Can I use IF in conditional formatting?

You can, but you rarely need it. The rule only needs a TRUE or FALSE result, so write the condition itself, such as =AND($E2="Open",$C2<TODAY()), instead of =IF(…,TRUE,FALSE).

Practise it in a lab

Related guides

Reading is step one. Doing is step two.

Every guide links to a lab where you build the same calculation in an online spreadsheet and get instant feedback.

Open the lab