ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Data tools
  3. Conditional Formatting With a Formula in Excel

Conditional Formatting With a Formula in Excel

By ExcelReady Team·Updated November 1, 2026·5 min read

The short answer

To use a conditional formatting formula in Excel, select the cells, go to Home > Conditional Formatting > New Rule and choose Use a formula to determine which cells to format. Type a formula that returns TRUE or FALSE for the top-left cell, such as =$E2>5, and pick a format. Excel colours every cell where the formula is TRUE.

Key takeaways

  • The formula must return TRUE or FALSE, and you write it for the top-left cell of the selection.
  • Lock the column with $ (=$E2) to colour whole rows; lock both ($H$1) for one fixed input cell.
  • AND, OR, COUNTIF, SEARCH and TODAY all work inside a rule.
  • Test the formula in a spare column first: if it shows TRUE in the right rows, the rule will work.
  • Manage Rules lets you edit the formula, the Applies to range and the rule order.
On this page+
  1. How a formula rule works
  2. How to create a conditional formatting formula rule
  3. Where do the $ signs go?
  4. Conditional formatting formula examples
  5. Test the formula in a cell first
  6. How to edit or delete a formula rule
  7. Why isn't my conditional formatting formula working?
  8. Practise it

A conditional formatting formula lets you colour cells by any rule you can write in Excel, not just the ready-made ones like "greater than". The formula returns TRUE or FALSE, and Excel applies the format wherever it's TRUE. This guide shows how to set one up, where the $ signs go, and a set of formulas you can copy for common tasks.

How a formula rule works#

A formula rule asks one question per cell: "is this formula TRUE here?" You write the formula once, for the top-left cell of the range you selected. Excel then adjusts it for every other cell, exactly as if you had copied the formula across and down.

So if you select A2:E9 and type =$E2>5, Excel checks $E2>5 for row 2, $E3>5 for row 3, and so on. If you are new to conditional formatting, start with the beginner's guide to conditional formatting.

The examples use this task list in A1:E9:

ABCDE
1TaskOwnerDueStatusHours
2T-101Jamal4-Mar-2024Open6
3T-102Sara6-Mar-2024Done3
4T-103Wei8-Mar-2024Open2
5T-104Jamal11-Mar-2024Open9
6T-105Sara13-Mar-2024Done7
7T-106Wei15-Mar-2024Open4
8T-107Jamal18-Mar-2024Done5
9T-108Sara20-Mar-2024Open8

How to create a conditional formatting formula rule#

  1. Select the cells to format, for example A2:E9. Start at row 2 so the header isn't included.
  2. Go to Home > Conditional Formatting > New Rule.
  3. Choose Use a formula to determine which cells to format.
  4. In the box, type =AND($D2="Open",$E2>5).
  5. Click Format, pick a fill colour on the Fill tab, and click OK.
  6. Click OK again.

Rows 2, 5 and 9 turn coloured: T-101, T-104 and T-108 are open and take more than 5 hours. The steps and menu names are the same in Excel for Mac.

Where do the $ signs go?#

The $ signs decide which part of the formula moves as Excel applies it to each cell. This is the same idea as absolute and relative references in normal formulas.

You want toFormula patternWhy
Colour whole rows based on one column=$E2>5Column E locked, row moves
Colour each cell by its own value=E2>5Both move, each cell checks itself
Compare every row with one input cell=$B2=$H$1H1 fully locked
Compare with a total or average=E2>AVERAGE($E$2:$E$9)The range stays fixed

The row pattern, $E2, is the one people get wrong most often. Without the $, the cell in column A checks A2, column B checks B2, and so on, so only some cells in each row change colour. The guide to highlighting a whole row based on a cell value covers this in depth.

Conditional formatting formula examples#

These formulas all assume the selection starts at row 2. Change the column letters to match your data.

GoalFormulaResult on the task list
Open tasks=$D2="Open"5 rows
Open and over 5 hours=AND($D2="Open",$E2>5)T-101, T-104, T-108
Done or under 3 hours=OR($D2="Done",$E2<3)4 rows
Hours above average (5.5)=E2>AVERAGE($E$2:$E$9)6, 9, 7 and 8
Overdue and not done=AND($C2<TODAY(),$D2<>"Done")Depends on today's date
Owner matches a name in H1=$B2=$H$1Rows for that person
Repeated task IDs=COUNTIF($A$2:$A$9,$A2)>1None in this list
Every other row=MOD(ROW(),2)=0Rows 2, 4, 6, 8
Empty cells=B2=""None in this list
Text contains a word=ISNUMBER(SEARCH("urgent",$A2))Rows with "urgent" anywhere

For the overdue rule, if today were 12 March 2024, T-101, T-103 and T-104 would be coloured: they're due before today and still open. TODAY updates each day, so the rule keeps up on its own. For repeated values, the guide to highlighting duplicates has more variations.

Test the formula in a cell first#

The easiest way to debug a rule is to type the same formula in a spare column. In F2, type:

Excel formula
=AND(D2="Open",E2>5)

It shows TRUE. Fill it down to row 9 (Windows: Ctrl+D; Mac: ⌘D). You'll see TRUE in rows 2, 5 and 9 and FALSE everywhere else. If the TRUE values are in the right rows, the formula is right. Copy it into the rule, add the $ signs where needed, and delete the test column.

How to edit or delete a formula rule#

Go to Home > Conditional Formatting > Manage Rules. Set Show formatting rules for to This Worksheet to see every rule on the sheet. From here you can:

  • Edit Rule to change the formula or the format.
  • Change Applies to to make the rule cover more rows, such as =$A$2:$E$200.
  • Use the arrows to change the order. Rules higher in the list win when two set the same format.
  • Tick Stop If True (Windows) so lower rules don't apply when a rule matches.
  • Delete Rule to remove it.

To remove all rules from a range, select it and choose Home > Conditional Formatting > Clear Rules > Clear Rules from Selected Cells.

Why isn't my conditional formatting formula working?#

Check these common mistakes in order:

  1. Written for the wrong row. If the selection starts at row 2 but the formula says $E1, every result is shifted by one row. Write it for the first selected row.
  2. Missing or extra $. =E2>5 on a row rule colours single cells, not rows. =$E$2>5 checks only E2, so every row gets the same result.
  3. Formula in quotes. If you type ="=$E2>5" or Excel adds quotes after editing, the rule compares text. Remove the quotes.
  4. Text compared without quotes. =$D2=Open fails. Use =$D2="Open".
  5. Numbers stored as text. "9" stored as text isn't greater than 5 in the way you expect. Convert the column to numbers.
  6. A higher rule wins. Another rule sets the same fill first. Check the order in Manage Rules.

For colour based on size rather than a test, see data bars, colour scales and icon sets.

Practise it#

Formula rules combine two skills that tests check all the time: logical formulas and the $ sign. Practise conditional formatting in a live spreadsheet, including colouring whole rows with a formula rule. Then practise absolute references until the $ signs feel natural. Try the rule-test exercise on this page first.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Before making a rule, test its formula. In F2, type a formula with AND that returns TRUE when the status in D2 is Open and the hours in E2 are more than 5.

fx
ABCDEFG
1
Task
Owner
Due
Status
Hours
Rule test
2
T-101
Jamal
45355
Open
6
3
T-102
Sara
45357
Done
3
4
T-103
Wei
45359
Open
2
5
T-104
Jamal
45362
Open
9
6
T-105
Sara
45364
Done
7
7
T-106
Wei
45366
Open
4
8
T-107
Jamal
45369
Done
5
9
T-108
Sara
45371
Open
8
10
11
12

Tip: AND takes the two tests separated by a comma: D2="Open" and E2>5.

Practise this in a lesson

LessonConditional formattingMake important numbers stand out: highlight values over a limit, duplicate IDs and the top 3, then color whole rows with a formula rule and a $ on the column.LessonRelative vs absolute references ($)Lock a cell with $ so it doesn't move when you copy a formula, one of the most-tested Excel skills.

Frequently asked questions

How do I use a formula in conditional formatting?

+

Select the cells, go to Home > Conditional Formatting > New Rule, choose Use a formula to determine which cells to format, type a formula that returns TRUE or FALSE, set the format and click OK.

Why is my conditional formatting formula not working?

+

The most common causes are writing the formula for the wrong row, missing or extra $ signs, and typing the formula in quotes. Write it for the first cell of the selection and check the $ signs.

How do I use IF in conditional formatting?

+

You don't need IF. The rule already means if this is TRUE, apply the format. Write just the test, such as =$D2="Open" instead of =IF($D2="Open",TRUE,FALSE).

Can conditional formatting use two conditions?

+

Yes. Use AND when both must be true, such as =AND($D2="Open",$E2>5), or OR when either one is enough, such as =OR($D2="Open",$E2>5).

How do I apply conditional formatting based on another cell?

+

Refer to that cell in the formula. To compare with one fixed cell, lock it fully, as in =$B2=$H$1. To compare with a cell in the same row, lock only the column, as in =$E2>$F2.

Sources

  • Use conditional formatting to highlight information - Microsoft Support
  • Switch between relative, absolute, and mixed references - Microsoft Support
  • AND function - Microsoft Support

Written and checked by the ExcelReady Team. First published November 1, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. How a formula rule works
  2. How to create a conditional formatting formula rule
  3. Where do the $ signs go?
  4. Conditional formatting formula examples
  5. Test the formula in a cell first
  6. How to edit or delete a formula rule
  7. Why isn't my conditional formatting formula working?
  8. Practise it

Keep reading

Data tools· 5 min read

Conditional Formatting in Excel: Highlight What Matters

Conditional formatting colors cells automatically when they meet a rule. Select the cells, go to Home > Conditional Formatting, and pick a rule such as Highlight Cells Rules > Greater Than. To color whole rows, use New Rule > Use a formula, with a $ before the column letter: =$E2>5000. Rules update whenever values change.

Data tools· 5 min read

Highlight an Entire Row Based on a Cell Value

To highlight a row based on a cell value, select the whole table without the header, such as A2:E9, then go to Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format. Type =$D2="Late", choose a fill colour. The $ locks column D, so each row checks its own status.

Data tools· 6 min read

Find and Highlight Duplicates in Excel

To highlight duplicates in Excel, select the cells, go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values, and click OK. Every value that appears more than once turns red. To flag or count repeats with a formula instead, use COUNTIF: =COUNTIF($A$2:$A$9,A2)>1 is TRUE for a duplicate.

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free