To use a conditional format with an IF statement in Excel, you create a conditional formatting rule that uses a formula beginning with =IF(...) that returns TRUE or FALSE. For example, to highlight cells in B2:B10 where the value is greater than 100, select the range, go to Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format, enter =IF(B2>100,TRUE,FALSE) (or simply =B2>100, which works the same way), and set a format. The rule applies the format only when the formula evaluates to TRUE.
What Conditional Formatting with IF Actually Does
Conditional formatting is a feature that changes a cell’s appearance (fill color, font, borders) based on its value or a formula you supply. When you combine it with an IF statement, you are not using IF to return a value into the cell; instead, IF is used inside the formula to decide whether the formatting should trigger. The formula must return a Boolean TRUE or FALSE. Excel treats any non-zero number as TRUE, but it is cleaner to use comparisons or an explicit IF that returns TRUE/FALSE.
For example, to highlight overdue tasks where the due date is before today and the status is not “Done”, you might use a formula like =IF(AND($C2<TODAY(),$D2<>"Done"),TRUE,FALSE). This works because the AND function returns TRUE only when both conditions are met, and IF passes that TRUE to the formatting engine.
How to Write a Conditional Formatting IF Formula
The process is straightforward, but the formula must follow Excel’s rule for conditional formatting: it must be written relative to the top-left cell of the selected range. Here are the steps for Excel 365 on Windows (Mac steps are similar; use Cmd instead of Ctrl):
- Select the range you want to format, for example
B2:B10. - Go to Home > Conditional Formatting > New Rule.
- Choose Use a formula to determine which cells to format.
- In the formula box, enter your IF formula. For the range B2:B10, the formula should reference the first cell, B2, with relative row (no $ before the row number) so it adjusts for each row.
- Click Format, choose a fill or font color, then click OK twice.
On a Mac, the menu path is the same, but keyboard shortcuts use Cmd (e.g., Cmd+Z for undo). In Excel for the web, the path is identical, but some advanced options may be limited; basic formula-based rules work the same.
Common IF Formulas for Conditional Formatting
Here are several practical examples you can adapt. In each, assume the range starts at A2 and you are formatting based on that row.
- Highlight values above a threshold:
=IF(A2>100,TRUE,FALSE)– highlights cells greater than 100. - Highlight blank cells:
=IF(ISBLANK(A2),TRUE,FALSE)– highlights empty cells. - Highlight duplicates:
=IF(COUNTIF($A$2:$A$100,A2)>1,TRUE,FALSE)– highlights any value that appears more than once. - Highlight based on another column:
=IF($B2="Yes",TRUE,FALSE)– highlights cells in column A when column B says “Yes”. - Highlight entire row: Select A2:D10 and use
=IF($B2="Urgent",TRUE,FALSE)– the dollar sign locks the column so the rule checks column B for every cell in the row.
Remember: the formula must be relative to the active cell in the selection. If you select A2:D10, the active cell is usually A2, so your formula should reference A2 (or $B2 if you want to check column B).
IF vs. Direct Comparison: Which to Use?
You might wonder why use IF at all when a direct comparison like =A2>100 works. The truth is, for simple conditions, the direct comparison is shorter and equally effective. The IF function becomes useful when you need to return a specific TRUE/FALSE based on a more complex logic that isn’t a simple comparison, or when you want to make the rule’s logic more readable. For instance, =IF(OR(A2="",B2=""),TRUE,FALSE) is clearer than =OR(A2="",B2="") to some users, though the latter is identical. In practice, use the simplest formula that works. Overusing IF can make rules harder to debug.
Common Problems and How to Fix Them
Conditional formatting with IF formulas often fails for a few predictable reasons:
- Wrong relative references: If you enter
=IF($A$2>100,TRUE,FALSE)for a range A2:A10, every cell will check A2, not its own row. Use relative references (no $) for the row that changes. - Formula returns a number or text instead of TRUE/FALSE: Excel will treat any non-zero number as TRUE, but text like “TRUE” (as a string) will not work. Ensure your IF returns TRUE or FALSE, or use a comparison that returns a Boolean.
- Applying to the wrong range: If you select A2:A10 but want to format based on column B, you must reference $B2 in the formula. If you forget the $, Excel will check the cell itself, not column B.
- Using IF with AND/OR incorrectly: Remember that AND and OR are functions, not operators. Write
=IF(AND(A2>10,B2<5),TRUE,FALSE), not=IF(A2>10 AND B2<5,TRUE,FALSE).
If a rule doesn’t work, select a cell in the range and go to Conditional Formatting > Manage Rules to see the formula as Excel interprets it. Also, test the formula in a regular cell (e.g., in C2) to see if it returns TRUE for a cell that should be highlighted.
Conditional Formatting vs. IF Formula in a Cell
A common confusion is the difference between using IF in a conditional formatting rule and using IF in a cell formula. When you put =IF(A2>100,"High","Low") in a cell, you get text output. That text does not change the cell’s appearance unless you also apply conditional formatting based on that text. Conditional formatting with IF directly changes the appearance without adding an extra column. The two approaches can be combined: you might have an IF formula in a helper column, then use a simple conditional formatting rule based on that helper column’s value (e.g., highlight cells where the helper says “High”). That is often easier to maintain than a complex formula inside the rule.
Frequently Asked Questions
Can I use nested IF statements in conditional formatting?
Yes, you can nest IF functions, but it is usually simpler to use AND, OR, or other logical functions. For example, =IF(A2>100,IF(B2="Yes",TRUE,FALSE),FALSE) works, but =AND(A2>100,B2="Yes") is shorter and does the same thing. Nested IFs become hard to read and debug, so prefer logical functions when possible.
Why is my conditional formatting rule not working even though the formula is correct?
Check the applied range and the active cell. If you selected A2:A10 but the active cell was A1, your formula might reference A1 instead of A2. Also verify that the formula returns TRUE (not “TRUE” as text) and that you have not accidentally set a conflicting rule that overrides it. Use Manage Rules to see the order and check “Stop If True” options.
How do I apply conditional formatting to an entire row based on one cell?
Select the entire row range (e.g., A2:D10) and use a formula with a locked column reference, like =IF($B2="Urgent",TRUE,FALSE). The dollar sign before B keeps the column fixed, while the row number (2) is relative and adjusts for each row. This highlights all cells in a row when column B meets the condition.
Can I use conditional formatting with IF to highlight text that contains a specific word?
Yes, use the ISNUMBER and SEARCH functions. For example, to highlight cells containing “urgent”, use =IF(ISNUMBER(SEARCH("urgent",A2)),TRUE,FALSE). SEARCH is case-insensitive; use FIND for case-sensitive. This works because SEARCH returns a number if found, and ISNUMBER converts that to TRUE.
Does conditional formatting with IF work in Google Sheets?
Yes, Google Sheets supports custom formulas in conditional formatting under Format > Conditional formatting > Custom formula is. The syntax is similar, but you use the same relative reference logic. For example, =IF(A2>100,TRUE,FALSE) works. However, some functions like SEARCH differ slightly (they are case-insensitive by default), and the menu path is different from Excel.
Alternatives to IF in Conditional Formatting
If you find yourself writing long IF formulas, consider these alternatives:
- Built-in rules: For common cases like above/below average, duplicates, or text containing, use the preset rules under Conditional Formatting > Highlight Cells Rules or Top/Bottom Rules. They are faster and less error-prone.
- Use a helper column: Create a column with an IF formula that returns “Yes”/”No” or TRUE/FALSE, then apply a simple conditional formatting rule based on that column’s value. This separates logic from formatting and is easier to audit.
- Use boolean logic directly: Instead of
=IF(AND(A2>10,B2<5),TRUE,FALSE), use=AND(A2>10,B2<5). It is shorter and equally valid.
Remember that conditional formatting rules are recalculated whenever the worksheet changes, so performance can degrade if you have thousands of rules with complex formulas. Keep your formulas simple and limit the range to the actual data area.
Related
- Count Rows in MySQL: The 5 Best Ways
- How to Sum All Subtotals in Excel (3 Ways)
- Bukit Batok Printing Shop: Quick Guide & Top Picks
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Excel Date Minus 1 Month? Formula and Date RulesTo subtract one calendar month from an Excel date, use =EDATE(A1,-1), where A1 contains a real Excel date.…
- Power Automate Desktop String Functions ExplainedPower Automate Desktop provides a set of string functions—such as Substring, IndexOf, Replace, ToUpper, and Trim—that let you…
- Excel Date Difference: Formulas for Days, Months & YearsTo find the number of days between two dates in Excel, subtract the earlier date from the later…
- XLOOKUP Example With SUM in ExcelWith product names in A2:A5, monthly values in B2:D5, and the product to find in E2, use =SUM(XLOOKUP(E2,A2:A5,B2:D5)).…
- Filter Excel Data by Text: Steps and Useful OptionsTo filter Excel data by text in Microsoft 365 for Windows, select a cell in your data, choose…
- Power Automate left string function?The left() function in Power Automate returns a specified number of characters from the beginning (left side) of…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.