Sub topic 7
Controlling Which Cells a Rule Covers
This chapter assumes you can select ranges, write simple formulas, and apply a built-in rule from the Home tab. Here you will learn how the Applies to range decides where a rule works. It is the setting behind most "my rule highlights the wrong cells" problems.
What the Applies to range is
Every conditional formatting rule has an Applies to range. This is the set of cells Excel checks and formats with that rule. Cells outside the range are never evaluated.
When you create a rule, Excel fills in the range from your current selection. You can change it later in the Rules Manager. To open it, choose Home > Conditional Formatting > Manage Rules.
The range can be:
- A single block, such as
$A$2:$E$50. - Several blocks separated by commas, such as
$A$2:$A$50,$C$2:$C$50. - A whole column, such as
$C:$C. Rules on whole columns are easy to set up but can slow a large workbook.
Excel writes the range with absolute references (dollar signs) by default. This is normal. It does not affect how references inside a formula behave.
Why the selection matters for formula rules
For a formula-based rule, the active cell at the moment you create the rule is the reference point. Excel writes your formula as if it sits in that cell. It then adjusts the formula for every other cell in the range.
Suppose you select A2:E50, with A2 as the active cell, and enter this rule:
=$C2>1000For the cell B2, Excel evaluates =$C2>1000. For B3, it evaluates =$C3>1000. The column stays fixed because of the $, and the row moves with the cell. The result is that a whole row is highlighted when its column C value exceeds 1000.
If the active cell was A5 instead, Excel would read $C2 relative to A5. Each row would then check a cell three rows above it, which is a common source of off-by-some-rows errors. Always write the formula for the top-left cell of the range.
Editing the range
To change where an existing rule applies:
- Select any cell in the area, then open Home > Conditional Formatting > Manage Rules.
- Set Show formatting rules for to This Worksheet, so you see every rule.
- Click the rule, then edit the Applies to box. You can type a new range or click the range selector and drag on the sheet.
- Click OK.
Changing the range does not rewrite the formula. If you move the range down by two rows, the formula still refers to the cells it did before, relative to the original top-left cell. Check that the formula still matches the new top-left cell.
Rules that grow with your data
If you insert rows inside the range, Excel extends the range automatically. Rows added at the bottom edge often fall outside it. Two ways to avoid this:
- Convert the data to a table with Ctrl+T. Rules applied to table columns expand as rows are added.
- Apply the rule to a larger range, such as
$A$2:$E$500, and make the formula ignore blank rows.
The second option works with a formula like this:
=AND($B2<>"",$C2="")This highlights rows where column B has an entry and column C is still empty. Blank rows are skipped because column B is blank there.
Splitting and overlapping ranges
Copying and pasting cells can split one rule into several rules with smaller ranges. Excel does this when you paste into the middle of a formatted area. The Rules Manager then lists many near-identical rules.
You can repair this by editing one rule to cover the whole area and deleting the duplicates. Different rules can also overlap on the same cells. When they do, rule order decides which formatting wins. That is covered in a later chapter.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Wrong rows are highlighted, shifted by a few rows | Active cell was not the top-left cell when the rule was created | Edit the rule and rewrite the formula for the top-left cell |
| Only one column is highlighted instead of the row | The column letter has no `$` | Use `$C2`, not `C2` |
| New rows at the bottom are not formatted | The range ends at the last old row | Extend the range or use a table |
| Many duplicate rules appear | Copy and paste split the rule | Merge into one rule with one range |
Exercise
A rule =$C5>1000 was created with A2:E50 selected and A2 as the active cell. Which cell does the rule test when Excel evaluates cell B2, and why is this a problem?
Show answer
Relative to the active cell A2, the formula $C5 points three rows down. For B2, Excel tests $C5. Every row therefore checks the value three rows below it, so highlighting is shifted. Fix this by editing the rule to =$C2>1000, which is written for the top-left cell A2.
Exercise
You want a rule to cover A2:E500 so new records are formatted when you add them, but only rows with an entry in column B should be checked. What formula do you write for the top-left cell A2?
Show answer
Use a formula such as =AND($B2<>"",$C2>1000). The $B2<>"" test makes blank rows evaluate to FALSE, so they stay unformatted.