Sub topic 9
Getting references right: relative, absolute and mixed
Conditional formatting rules that use formulas fail more often because of cell references than for any other reason. This chapter explains how Excel reads a reference inside a rule, how to choose between relative, absolute and mixed references, and how to diagnose a rule that highlights the wrong cells. It assumes you can write simple formulas such as =A1+B1, select ranges, and have already created a formula-based rule in the New Formatting Rule dialog.
How Excel evaluates a rule formula
A formula-based rule is written once but evaluated for every cell in its Applies to range. Excel does this by treating the formula as if it were typed into the active cell, which is the cell that has focus when you open the dialog. Excel then adjusts the relative parts of the formula for every other cell in the range, just as it does when you copy a formula.
This gives one practical rule: the formula you write must be correct for the active cell. Excel derives the formula for all other cells from that one.
Suppose a rule applies to $A$2:$E$50, the active cell is A2, and the formula is =$C2>1000. Excel evaluates it like this:
| Cell being formatted | Formula Excel evaluates |
|---|---|
| A2 | `=$C2>1000` |
| D2 | `=$C2>1000` |
| A3 | `=$C3>1000` |
| E50 | `=$C50>1000` |
The column letter never changes because of the $. The row number follows the cell being formatted.
The three reference types
A reference can lock its column, its row, both, or neither. The $ sign marks the part that is locked.
| Type | Example | Column shifts? | Row shifts? | Typical use in a rule |
|---|---|---|---|---|
| Relative | `C2` | Yes | Yes | Comparing each cell with its own neighbor |
| Absolute | `$C$2` | No | No | A fixed threshold cell or fixed lookup range |
| Mixed, column locked | `$C2` | No | Yes | Formatting an entire row from one column |
| Mixed, row locked | `C$2` | Yes | No | Formatting an entire column from one header cell |
In the Rules Manager's formula box, the F4 key cycles through the four forms (C2, $C$2, C$2, $C2) when the cursor is inside a reference.
Mixed references: formatting whole rows
To highlight a whole row based on one column, lock the column and leave the row relative.
=$C2>1000Applied to $A$2:$E$50 with A2 active, every cell in a row checks the same column C cell in its own row. If any row has a value above 1000 in column C, all five cells in that row are highlighted.
If you leave out the $, the rule changes meaning:
=C2>1000Now column B checks column C... no, it checks column D: the column reference shifts one step right for each step right in the range. Only column A would test its own row's column C value. Each column in the range tests a different column, so the highlighting looks scattered.
Absolute references: fixed thresholds and ranges
Use absolute references when the rule must always point to the same cell or range. A threshold stored in a cell is the usual case. Suppose H1 holds the target value, so changing H1 changes the formatting.
=$C2>$H$1The column and row of the threshold are both locked, so every cell in the range compares column C of its own row with H1. Without the locks, =$C2>H1 would compare row 3 with H2, row 4 with H3, and so on, because H1 is relative.
The same applies to counting ranges. This rule from the topic marks duplicates:
=COUNTIF($A$2:$A$100,$A2)>1The counted range is fully absolute because every cell must be compared against the whole list. The criterion $A2 is relative in the row, so each row is counted against its own value. If the counted range were A2:A100, it would slide down and shrink as the rule moved down the sheet, which gives wrong counts.
Mixed references: formatting by column
Lock the row and leave the column relative when each column needs its own result based on values in a fixed row. A common case is highlighting the highest value in each column. Apply the rule to B2:E50 with B2 active:
=B2=MAX(B$2:B$50)For C5 Excel evaluates =C5=MAX(C$2:C$50). The compared cell moves with the cell being formatted. The range moves across the columns but its rows stay fixed, so each column is judged against its own values only.
Compare this with a fully absolute range, $B$2:$E$50. That version finds one maximum for the whole block and highlights only the single largest value overall.
The active cell trap
Because Excel reads the formula relative to the active cell, a wrong active cell shifts every result. Two things cause this:
- You select the range by dragging from the bottom-right to the top-left, or by using Shift+click, so the active cell is not the top-left cell.
- You open the Rules Manager and edit a rule while a different cell is selected.
For example, you select A2:E50 but the active cell is A1 when you type =$C2>1000. Excel treats the formula as written for A1, so row 2's cell checks column C of row 3, and the highlight appears one row above the row that meets the condition.
To avoid this:
- Before creating the rule, select the range so the active cell is the top-left cell. Click the first cell, then Shift+click the last one.
- Write the formula for that top-left cell.
- When editing an existing rule, first select the top-left cell of the rule's Applies to range, then open the Rules Manager.
Diagnosing wrong results
The pattern of wrong highlighting usually tells you which reference is wrong.
| Symptom | Likely cause | Fix |
|---|---|---|
| Highlight is one or more rows above or below the matching row | Active cell was not the top-left cell | Select the top-left cell and rewrite or re-enter the formula |
| Only the first column of the row is highlighted | Column in the reference is not locked | Change `C2` to `$C2` |
| Every cell is highlighted, or none are | Row is locked when it should shift, as in `$C$2` | Change `$C$2` to `$C2` |
| Highlighting drifts diagonally, with some rows wrong | Threshold or lookup range is relative | Change `H1` to `$H$1`, or `A2:A100` to `$A$2:$A$100` |
| Each column compares against the whole block instead of itself | Row-locked reference should be used instead of fully absolute | Use `B$2:B$50` instead of `$B$2:$E$50` |
To check a rule, pick two or three cells at the edges of the range, such as the first, the last, and one in the middle. Work out by hand what the formula becomes for each. Then compare the result with what you see on the sheet.
A quick decision method
When writing a reference in a rule, ask two questions for each part of the formula:
- As the rule moves across columns, should this part follow the cell being formatted? If not, lock the column with
$. - As the rule moves down rows, should this part follow the cell being formatted? If not, lock the row with
$.
For =AND($B2<>"",$C2=""), which finds rows where column B has an entry and column C is empty, both references answer "no" to the first question and "yes" to the second. That gives $B2 and $C2.
Exercise
A rule applies to $A$2:$E$50 and highlights a row when column D is blank. You select the range by dragging from E50 up to A2, so the active cell is E50. You type =$D2="" and click OK. Rows are highlighted incorrectly. What does Excel actually evaluate for cell A2, and how do you fix the rule?
Show answer
Excel treats the formula as written for the active cell E50, where $D2 is 48 rows above E50. For A2 the reference moves up by the same amount from row 2, so it points to a row above row 2 (an invalid position, so the rule does not work as intended), and the results are shifted for every other row. Fix it by selecting the range so that A2 is the active cell (click A2, then Shift+click E50), or by opening the rule in the Rules Manager with A2 selected, and entering =$D2="". The column stays locked and the row is relative to the top-left cell.
Exercise
A threshold is stored in cell H1. You want cells in B2:B50 to be highlighted when they exceed it. Which formula is correct with B2 active: =B2>H1, =B2>$H$1 or =$B$2>$H$1? Why do the other two fail?
Show answer
=B2>$H$1 is correct. In =B2>H1 the H1 reference is relative, so B3 would be compared with H2, B4 with H3, and so on. In =$B$2>$H$1 the compared cell is locked to B2, so every cell in the range gets the same result as B2 instead of being judged on its own value.