Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Conditional Formatting with Formulas: How-To

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Excel conditional formatting with a formula lets you highlight cells based on a logical test you write yourself, rather than a fixed rule like "greater than 100." The trick is that your formula returns TRUE or FALSE for the top-left cell of the selected range, and Excel copies it across and down automatically using relative and absolute references. If you need to highlight an entire row when one cell matches, colour duplicate entries across two columns, flag expired dates, or shade tasks by owner, a formula rule is the only way to do it. Everything here uses the built-in Conditional Formatting menu on Windows desktop and Excel for the web; the Mac menu labels are nearly identical, and the ribbon layout can differ slightly by version, device and region. Mobile apps have a reduced set, so build and edit formula rules on a computer where possible.

What You'll Need

  • Excel for Microsoft 365, Excel 2021 or 2019 (desktop, Windows or Mac) or Excel for the web, signed in with your Microsoft account.
  • A worksheet with data already in place, ideally laid out as a clean table with one header row and no blank rows or merged cells inside the data range.
  • A clear idea of the test you want: which cell holds the trigger value, and what should turn TRUE.
  • Write and test the formula in a normal cell first. It must return TRUE or FALSE before you paste it into the rule.

Step-by-Step

  1. Select the cells you want to format, not the cells that hold the values being tested. This is the most important step. If you want entire rows shaded, drag the selection across the whole table body: for example, A2:D100. Do not include the header row unless you want it tested too.
  2. Note the active cell of your selection. When you select a block, the first cell you clicked is white and stays active, and Excel writes your formula as if that cell were the only one selected. Any relative reference you type is offset from that cell as the rule is filled across and down.
  3. Write and test the formula in a spare cell outside the data first. For example, in cell F2 type =$B2="Overdue" or =AND($B2<>"",$B2<TODAY()). Press Enter and confirm it shows TRUE or FALSE with no error. Delete the test afterwards.
  4. Open the rule dialog. Go to Home > Conditional Formatting > New Rule, then choose Use a formula to determine which cells to format. The formula box appears at the bottom of the dialog.
  5. Paste or type the formula exactly as tested, without the leading equals sign being removed. Excel accepts the equals sign here. Do not add quotation marks around the whole formula, and do not wrap the formula in an IF function that returns text; the rule needs TRUE, not "Yes".
  6. Click Format and set the look you want: Fill for background colour, Font for bold or a colour change, Border for outlines. Keep it simple. A pale fill plus bold text reads better than a bright fill, especially on a large sheet.
  7. Click OK twice. The preview in the dialog updates as you change formatting, but the rule is only applied when you confirm both dialogs. If nothing changes on the sheet, the formula is returning FALSE or FALSE-equivalent, not mis-formatting.
  8. Test with real changes. Edit a value in the key cell and watch the row react. Undo it. If the formatting does not follow, check the reference type in the next step.
  9. Fix references deliberately. Use $B2 (column locked, row free) when every row is judged by the same column. Use B$2 (row locked, column free) when every column in a row is judged by the same row. Use $B$2 only for one fixed threshold cell. Use no dollar signs when you want the reference to shift in both directions.
  10. Manage the rule. Go to Home > Conditional Formatting > Manage Rules, then set Show formatting rules for: This Worksheet to see every rule. Use the arrow buttons to reorder, and remember that rules run top-down and the first match that stops processing wins if you tick Stop If True.

Common Mistakes

  • Selecting the wrong range. If you select the trigger column and write =B2="Overdue", only the trigger cells shade, not the rows.
  • Writing the formula against the wrong active cell. Rules written for A2 break if Excel treats B2 as the anchor. Reselect from the top-left cell you intend.
  • Quoting things that are not text. =A1=">100" treats the number 100 as text. Write =A1>100.
  • Forgetting blank cells. =A1<B1 is TRUE when A1 is empty and B1 is a positive number, so empty rows light up. Guard with =AND(A1<>"",A1<B1).
  • Using IF. =IF(A1>5,TRUE,FALSE) works but is pointless; the bare test is shorter and faster.
  • Assuming copy and paste carries the rule. Pasting values into other cells usually leaves formatting behind or duplicates it in an unexpected way. Use Manage Rules to check.

Tips

  • Deleting a row can leave the old rule behind in memory. Remove rules you no longer need from Manage Rules instead of relying on the rows disappearing.
  • For de-duplication, select A2:C100 and use the rule =COUNTIF($A:$A,$A2)>1 to shade every row that shares an ID.
  • For alternating bands, avoid formula rules and use Use a formula only when you need conditions; the built-in banded table style is lighter and survives sorting better.
  • Dates past a deadline: =AND($B2<>"",$B2<TODAY()) shades anything that has slipped, and it updates daily without editing the rule.
  • Reference names work too: =ISBLANK($C2) flags rows with a missing assignee.
  • If the sheet gets slow, reduce the number of separate rules. A single rule that ORs conditions with OR() is faster than four nearly identical rules.

Troubleshooting

If nothing is highlighted, first check that the formula really returns TRUE: put the same formula in an empty cell and confirm the output. If it returns FALSE, your references or comparison types are wrong. If it returns an error such as #VALUE!, you are probably comparing text to a number, or a date stored as text; use the correct type or convert the column. If the formula is true but nothing shows, the range selection was likely wrong; open Manage Rules and check the Applies to box. If the colour is there but hidden, look for a conflicting rule higher in the list, a table style that overrides, or cell fill with a white background. If a whole block lights up when only one row should, a missing dollar sign is usually to blame; test with $A$2 style references to isolate the culprit. If rules seem stuck after sorting or filtering, remember that rules are applied to fixed cell addresses, which is why absolute anchors are better for threshold cells. As a last resort, clear all rules from the range with Home > Conditional Formatting > Clear Rules and rebuild one rule at a time.

Frequently Asked Questions

Can the formula return text like "Yes"?

No. The test must resolve to TRUE or FALSE. Use a comparison, or wrap logic in AND and OR rather than returning a string.

How do I highlight the whole row when one cell says "Done"?

Select the full row range such as A2:F50, then use =$D2="Done", locking the column but leaving the row relative.

Why does my rule look one row off?

Your formula was anchored on the wrong cell. The formula must be written as if it applies to the top-left cell of the selected range, so reselect starting there and retest.

Can I copy a rule to another sheet?

Not directly through the clipboard reliably. Recreate it on the second sheet, or apply it to both sheets at once by grouping the sheet tabs before opening New Rule. Grouping can also affect edits, so ungroup immediately after.

Does conditional formatting work on Excel for the web?

Yes, including formula rules, though some advanced options and rule ordering are easier to manage on the desktop app.

How do I stop blanks from being formatted?

Add a non-blank check with AND, such as =AND($A2<>"",$A2<TODAY()), so empty rows stay untouched.