Conditional formatting in Excel: colour cells by a rule
Conditional formatting colours a cell automatically, based on its value: sales above target in green, overdue dates in red, duplicates in yellow. Unlike a fill colour you click by hand, the rule keeps working when the numbers change, which is exactly what a report that's refreshed every month needs.
The built-in rules
Select the range, then Home → Conditional Formatting → Highlight Cells Rules and pick a rule. These cover most real cases.
Greater Than / Less ThanSales above 10,000, balances below zero.Equal To / Text that ContainsEvery North, every description containing "overdue".A Date OccurringLast week, this month, next month.Duplicate ValuesIDs that appear twice in a list.Rules with a formula
New Rule → Use a formula to determine which cells to format lets you colour a whole row or use any condition. Write the formula for the first row and lock the column with $.
=$C2>10000Colours the whole row when column C is above 10,000.=$D2<TODAY()Colours rows with a due date in the past.=COUNTIF($A$2:$A$500, $A2)>1Colours every repeated ID.=MOD(ROW(), 2)=0Shades every other row.Common mistakes
- The whole range turns the same colour
- A formula rule without
$before the column checks the wrong cell for every row. Use=$C2>10000, not=C2>10000or=$C$2>10000. - Too many rules pile up
- Copying cells copies their rules too. Clean up in Conditional Formatting → Manage Rules.
- Numbers stored as text are ignored
- A greater-than rule doesn't see text. Convert the values to numbers first.
Tips
- Data Bars and Color Scales turn a column of numbers into a quick chart inside the cells.
- Conditional formatting changes only how cells look. To filter or count the coloured rows, use the same condition in COUNTIF or FILTER.
Frequently asked questions
How do I highlight cells greater than a value?
Select the cells, Home → Conditional Formatting → Highlight Cells Rules → Greater Than, type the value and pick a colour.
How do I highlight a whole row based on one cell?
Select the rows, New Rule → Use a formula, enter something like =$C2>10000 and choose a format. The $ keeps the check on column C.
How do I remove conditional formatting?
Home → Conditional Formatting → Clear Rules → Clear Rules from Selected Cells (or from the entire sheet).
Can I count cells by their colour?
Not directly. Count with the same rule instead: =COUNTIF(C2:C500, ">10000") counts the cells that the rule colours. See COUNTIF.
Related lessons
COUNTIFIFBold, italic & highlightFILTER