Use a Formula to Determine Which Cells to Format

Formulas & functions · Updated November 23, 2026

Yes, Excel lets you use a formula to determine which cells to format in Conditional Formatting. Open the Home tab, click Conditional Formatting > New Rule, choose Use a formula to determine which cells to format, enter a formula that returns TRUE for cells you want highlighted, then set a format and click OK. This gives you far more power than the built-in preset rules, because the formula can reference other cells, use functions, and apply logic that the standard options cannot express.

Why Use a Formula Instead of Preset Rules

The built-in Conditional Formatting presets (like Highlight Cells Rules or Top/Bottom Rules) only handle simple comparisons: greater than a number, text that contains a phrase, duplicate values, and so on. A formula rule can do anything a spreadsheet formula can do. For example, you can highlight an entire row based on a value in one column, format cells based on a date that is within the current week, or flag values that are above the average of a dynamic range. The formula rule is evaluated for each cell in the selected range, using the active cell as the anchor for relative references. That single distinction unlocks row-level formatting, cross-sheet comparisons, and logic that combines multiple conditions with AND, OR, and NOT.

How the Formula Rule Works (Relative vs. Absolute References)

When you create a formula rule, Excel treats the formula as if it were entered into the active cell (the first cell in your selection, usually the top-left). Excel then copies that formula logic across the entire selected range, adjusting relative references just like when you fill a formula down a column. This is the key to row-based formatting. Suppose you have a table with names in column A and sales in column B, and you want to highlight the entire row when sales exceed 5000. Select A2:C20 (the whole table), create a new formula rule, and enter =$B2>5000. The dollar sign locks the column B, but the row number 2 is relative, so for row 3 the formula becomes =$B3>5000, and so on. Because the rule applies to the whole selected range, every cell in a row where B is over 5000 gets formatted. If you had entered =B2>5000 without the dollar sign, the formatting would shift columns as well, producing erratic results. Always anchor the column with a dollar sign when you want the check to stay on one column while the row changes.

Step-by-Step: Creating a Formula-Based Rule

  1. Select the range of cells you want to format (for example, A2:C20).
  2. Go to Home > Conditional Formatting > New Rule.
  3. In the New Formatting Rule dialog, choose Use a formula to determine which cells to format.
  4. In the Format values where this formula is true box, type your formula. Use the active cell reference (usually the top-left of your selection) with the correct absolute/relative mix.
  5. Click Format to choose a fill color, font, or border, then click OK.
  6. Click OK again to apply the rule. The rule will appear in the Conditional Formatting Rules Manager, where you can edit, delete, or reorder it.

On a Mac, the steps are identical except the ribbon labels: Home tab, Conditional Formatting, New Rule, then the same dialog. In Excel for the web, the path is Home > Conditional Formatting > New Rule, and the formula box works the same way, though some advanced formatting options (like data bars with custom formulas) are limited.

Practical Examples of Formula Rules

  • Highlight upcoming deadlines within 7 days: With dates in A2:A100, select that range, use the formula =AND(A2>=TODAY(),A2<=TODAY()+7). This uses AND to check both conditions.
  • Highlight duplicate entries in a list: Select A2:A100 and use =COUNTIF($A$2:$A$100,A2)>1. The absolute range locks the whole list, while A2 is relative for each row.
  • Highlight cells that contain errors: Select the range and use =ISERROR(A2). This works for any error type (#N/A, #VALUE!, etc.).
  • Highlight alternating rows (banded rows): Select A2:C20 and use =MOD(ROW(),2)=0. This formats even-numbered rows. For odd rows, change to =1.
  • Highlight a row based on a dropdown selection: If column A has a status like “Overdue”, select the whole table and use =$A2="Overdue".

In each case, the formula must evaluate to TRUE for the cell to be formatted. Any formula that returns a number (like =A2>5) is treated as TRUE if the result is non-zero, but it is best practice to use logical functions that explicitly return TRUE or FALSE.

Common Mistakes and How to Fix Them

The most frequent error is forgetting the dollar sign in the column reference when you want row-based formatting. Another common issue is selecting the wrong range before creating the rule. The rule applies only to the range you selected when you created it; if you want to extend it later, use the Conditional Formatting Rules Manager to edit the “Applies to” field. A third mistake is using a formula that references the wrong row. If your selection starts at row 2, your formula should reference row 2 (like =$B2>5000), not row 1. If you reference row 1, the formatting will be off by one row. Also, remember that formulas in Conditional Formatting cannot use certain functions like INDIRECT with a dynamic reference in older versions, but in Excel 365, INDIRECT works fine. Finally, if your formula returns a #N/A error, the rule will not format anything; wrap it in IFERROR if needed, but usually you want the rule to be simple.

How Formula Rules Compare to Other Conditional Formatting Methods

Preset rules (like Color Scales, Data Bars, and Icon Sets) are visual and quick, but they do not allow custom logic. For example, a Color Scale always applies a gradient based on the lowest and highest values in the range; you cannot make it skip certain rows. A formula rule can. Data Bars have a built-in option to show only the bar, but you cannot conditionally show a bar only when a neighboring cell meets a criterion. Formula rules give you complete control over the fill, font, and border. The trade-off is complexity: formula rules require you to understand relative references and logical functions. For beginners, starting with presets and then moving to formulas when you hit a limitation is a natural path. Also note that formula rules are evaluated in order; if you have multiple rules on the same range, the first rule that returns TRUE will apply (unless you check “Stop If True”). This order matters when rules overlap.

Performance and File Size Considerations

Formula-based conditional formatting is recalculated every time the worksheet recalculates. If you apply a formula rule to a huge range (like A1:XFD1048576, the entire sheet), Excel may slow down noticeably. Keep the “Applies to” range as small as possible. Also, avoid using volatile functions like TODAY() or NOW() in formulas that cover thousands of cells, because they force recalculation on every change. If you need to check a date against today, consider putting =TODAY() in a helper cell and referencing that cell in your conditional formatting formula (e.g., =$A2>=$Z$1). This reduces recalculation load. In Excel 365, dynamic array functions like FILTER or SEQUENCE are not allowed inside conditional formatting formulas; you must use traditional functions. For large datasets, you can also use a table (Insert > Table) and apply conditional formatting to the table column, which automatically extends the rule to new rows.

Frequently Asked Questions

Why is my formula rule not working even though the formula returns TRUE when I test it in a cell?
Check the active cell reference. The formula in the rule must be written relative to the top-left cell of the selected range. If you selected A2:C20, the formula should reference A2 (or $A2, etc.). If you wrote =B1>5 but your selection starts at A2, Excel will check B1 for the first cell, which is wrong. Also, make sure the range in the “Applies to” box matches your selection; sometimes Excel changes it when you edit the rule.

Can I use a formula to format an entire row based on a cell in that row?
Yes. Select the entire row range (e.g., A2:C20), and use a formula with a locked column reference like =$A2="Yes". The dollar sign on the column is essential; without it, the formula would shift columns as it moves across the row, and the formatting would be inconsistent.

How do I apply a formula rule to multiple non-contiguous ranges?
You cannot select non-contiguous ranges and create one rule in a single step. Instead, create the rule for the first range, then open Conditional Formatting Rules Manager, click “Duplicate Rule”, and change the “Applies to” field to the second range. Alternatively, use a named range that combines the areas, but that is more complex.

Does the formula rule work with dates and times?
Yes. Dates are stored as numbers in Excel, so you can compare them with =A2>=DATE(2025,1,1) or use functions like TODAY(), EDATE(), or WEEKDAY(). For example, to highlight weekends, use =OR(WEEKDAY(A2)=1,WEEKDAY(A2)=7).

Can I use a formula rule in Google Sheets?
Yes, but the interface differs. In Google Sheets, select the range, go to Format > Conditional formatting, choose “Custom formula is” from the dropdown, and enter the formula. The same relative reference logic applies, but you do not need to use dollar signs as often because Google Sheets handles it slightly differently; however, for row-based formatting, the dollar sign on the column still works the same way.

Why does my rule disappear when I copy and paste cells?
Pasting over cells that have conditional formatting will overwrite the formatting rules unless you use Paste Special > Values or Paste Special > Formatting. To avoid losing rules, copy and paste only values, or use the Format Painter carefully. If you need to move a rule to a new range, use the Rules Manager to edit the “Applies to” field rather than copying the cells.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.