Conditional formatting changes how a cell looks when a rule is met, such as a fill color or bold text. It doesn’t change the value in the cell. A formula-based rule lets you define the condition yourself. The condition works like the test in an IF formula, so the formula has to return TRUE or FALSE. For the test syntax, see how to use if function in excel.
Set up the rule
- Select the cells to format. Start below the header row, such as A2:E100.
- On the Home tab, click Conditional Formatting, then New Rule.
- Choose “Use a formula to determine which cells to format.”
- Type the formula, starting with an equals sign.
- Click Format, choose a fill color or font style, then click OK twice.
The Applies to box shows the range the rule covers. It is filled in with your selection by default.
Write the formula for the top-left cell
The formula is written for the first cell of the selected range, the top-left one. Excel applies the same formula to every other cell by moving the references in the usual way.
For example, to highlight an entire row from A to E whenever column E says “Overdue”, select A2:E100 and use:
=$E2="Overdue"
The dollar sign before E keeps the column fixed, so every cell in each row checks column E of that same row. The row number has no dollar sign, so it changes as the rule moves down the sheet.
Example: duplicates
To highlight repeated values in A2:A200, select that range and use:
=COUNTIF($A$2:$A$200, A2)>1
COUNTIF counts how many times the current cell’s value appears in the full list. Any value that appears more than once is highlighted. The fixed range keeps the comparison on the whole list for every row. The COUNTIF pattern is covered in how to use countif in excel. This rule only highlights duplicates. To remove them, see excel formula to remove duplicates.
Example: weekend dates
To shade weekend dates in A2:A200, use:
=AND(A2<>"", WEEKDAY(A2, 2)>5)
With the second argument set to 2, WEEKDAY numbers Monday as 1 and Sunday as 7. Values of 6 and 7 are Saturday and Sunday, so the rule shades only those days.
The first test skips blank cells. Excel reads a blank as 0, and WEEKDAY returns a result for it too, so without that test a blank cell could be shaded by mistake.
Managing rules
To see, edit or reorder rules, click Conditional Formatting, then Manage Rules. If two rules set the same property, such as the fill color, the rule higher in the list wins. The Stop If True box on a rule stops the rules below it from running when that rule is met.
Why a rule doesn’t show
If the formatting doesn’t appear, check these:
- The formula doesn’t return TRUE or FALSE. A formula that returns text or a number, such as
=A2, won’t format the cell on its own. Use a comparison. - The starting cell is wrong. If the references are off by a row, the rule checks the wrong cells. Recheck the top-left cell of the selection.
- Another rule takes priority. A higher rule that sets the same fill color can hide the new one.
- The condition is not met. Test the formula in an empty cell to see whether it returns TRUE for a row you expect.