Sub topic 2
Choosing the range a rule applies to
This chapter assumes you can move around a Google Sheets spreadsheet, enter values and simple formulas, and select ranges such as A2:F100. It does not assume you have written a conditional formatting rule before. It does cover the range box in detail, because most rules that "don't work" have a range problem, not a condition problem.
What the range controls
Every conditional formatting rule has two parts:
- The range: the cells the rule is allowed to format.
- The condition: the test that decides, cell by cell, whether the format appears.
The range is a boundary. A cell outside the range is never formatted by that rule, whatever its value. A cell inside the range is formatted only if the condition is true for it.
The range also sets the reference point for formulas. When you write a custom formula later in this tutorial, Sheets reads it as if it were typed into the top-left cell of the range. Changing the range can therefore change what the formula means. This chapter covers the effect briefly, and the chapter on relative and absolute references covers it in depth.
Where the range is set
- Select the cells you want to format. This pre-fills the range.
- Open Format > Conditional formatting. The Conditional format rules sidebar appears on the right.
- Look at the Apply to range box at the top of the rule. This is the range for the rule.
- Set the condition under Format rules, choose a format, and click Done.
Selecting cells first is a convenience. The sidebar's range box is the actual source of truth, and you can edit it at any time. Click the text in the box and type a new range. You can also click the small grid icon at the right of the box. This opens a Select data range dialog where you drag over cells on the sheet.
Range notation you will use
The range box uses the same A1 notation as formulas.
| Notation | Meaning | Typical use |
|---|---|---|
| `A2:F100` | A fixed block, rows 2 to 100, columns A to F | A table with a known size |
| `C2:C` | Column C from row 2 down to the end of the sheet | A column that keeps growing |
| `A:A` | The whole of column A, including the header | Quick rules where the header does not matter |
| `A2:A100, C2:C100` | Two separate blocks, separated by a comma | Rules for columns that are not next to each other |
| `2:2` | The whole of row 2 | Formatting a single row |
Each form has trade-offs, covered in the sections below.
Fixed, open-ended, and whole-column ranges
Fixed ranges
A2:F100 formats only up to row 100. If you add data in row 101, the rule does not reach it. A fixed range is predictable, but you must remember to extend it. Use it when the table has a known, stable size.
Open-ended ranges
C2:C has no row number after the colon. It means "from C2 to the bottom of column C", so new rows are covered automatically. This is usually the best choice for a table that grows, and it skips the header in row 1.
An open-ended range can be applied to several columns at once:
A2:FEnter that text in the range box. The rule now covers every row below the header across columns A to F, for as long as the sheet has rows.
Whole-column ranges
C:C includes row 1. If your header says "Status", a rule such as "Text is exactly Done" will not affect it. But a rule such as "Cell is not empty" or a number rule like "Greater than 0" can affect a header unexpectedly. Prefer C2:C unless you want the header included.
Choosing the first row deliberately
The first row of the range is more than the place where formatting starts. It is the cell your custom formula is anchored to. Compare two versions of the same rule.
Range A2:F100:
=$C2="Done"Range A1:F100:
=$C2="Done"The text is identical, but the result is different. In the first version, the formula is read as written for cell A2, so each row tests its own column C. In the second version, the formula is read as written for A1, so it points one row below the cell being formatted. Every row ends up checking the status of the row beneath it, and the highlighting shifts up by one row.
This is the most common range mistake with custom formulas. The rule is simple: the row number in your formula must match the first row of the range. If the range starts at row 2, refer to row 2. If it starts at row 5, refer to row 5.
Multiple ranges in one rule
A single rule can cover several blocks. In the sidebar, click Add another range under the first range. You can also type ranges into one box, separated by commas.
Use this when separate blocks need the same logic and format. For example, a budget sheet might have monthly figures in B2:B13 and D2:D13, with a spacer column between them. One rule covers both:
B2:B13, D2:D13Pair the range with a built-in condition such as "Less than 0" and a red font color. Then you maintain one rule and not two.
Two points to keep in mind:
- With a custom formula, the anchor is the top-left cell of the first range listed. Keep the blocks aligned in the same rows, or the references can point to unintended cells in the other blocks.
- If the blocks need different conditions or formats, create separate rules. Combining them makes the rule harder to read without saving much work.
How ranges change as the sheet changes
Ranges are not frozen. Sheets updates them when you restructure the sheet, much as it updates formula references.
- Inserting rows or columns inside the range expands it. Insert a row between rows 10 and 11 of
A2:F100and the range becomesA2:F101. - Inserting rows just outside the edge usually does not expand it. A row added directly below the last row of a fixed range is not covered. This is another reason to use an open-ended range such as
A2:F. - Deleting rows shrinks the range. If you delete all the rows or columns the range covered, the rule has nothing to apply to.
- Cutting and pasting cells can split a rule into several rules, or move its range along with the cells. If you see unexpected extra entries in the sidebar after a cut and paste, this is the likely cause. A later chapter on managing rules covers cleanup.
- Pasting with formatting copies the conditional formatting along with the values. To avoid that, use Paste special > Values only.
The diagram shows a decision flow for picking the range at the time you create a rule.
Worked example: a task tracker
Suppose a sheet has a header in row 1 and tasks below it:
| A: Task | B: Owner | C: Hours | D: Status |
|---|---|---|---|
| Write spec | Ana | 6 | Done |
| Review code | Ben | 3 | In progress |
| Deploy | Ana | 2 | Not started |
The goal is to shade the Hours column red when the value is above 5, and to keep working as rows are added.
- Select any cell in column C, then open Format > Conditional formatting.
- In Apply to range, replace the text with
C2:C. This skips the header "Hours" and covers every row added later. - Under Format rules, open the dropdown and choose Greater than.
- Enter
5in the value box. - Under Formatting style, choose a light red fill.
- Click Done.
Row 2 (6 hours) turns red. Rows 3 and 4 stay unformatted. If you type a new task in row 5 with 8 hours, it turns red without any change to the rule.
Now suppose the same rule was set to C:C. The header "Hours" is text, not a number. Sheets treats text as larger than numbers in some comparisons, so a "Greater than" rule can sometimes flag a header. The exact behavior depends on the condition type. Using C2:C removes the question.
Checking a rule's range
When a rule seems wrong, check the range first, then the condition.
- Open the sidebar and click the rule. Read the Apply to range text exactly.
- Compare the first row of the range with any row number inside a custom formula.
- Check that every column you expect is listed, especially after inserting or moving columns.
- Look for several similar rules with small ranges. These are often left by earlier paste operations.
- Test the rule on a cell you know should match, and on one you know should not. This shows whether the range or the condition is the problem.
If a cell inside the range is never formatted, the condition is false for that cell. If a cell outside the range is not formatted, that is expected, because the rule cannot reach it. The range decides who is eligible, and the condition decides who is formatted.
Common range mistakes
- Range starts at the header row, formula points to row 2. The highlighting is shifted by one row.
- Range is too small. Rows added past row 100 are never formatted. Use an open-ended range.
- Range covers only the column being tested. To highlight a whole row, the range must span every column in the row, for example
A2:F100, not just the status column. - Range includes unrelated columns. A rule on
A2:Zformats blank cells and helper columns when the condition allows it. Limit the range to the columns that should change. - Overlapping rules with different ranges. Two rules can cover the same cell. The rule higher in the sidebar list wins when their formats conflict. The next chapters on rule order cover this.
Summary of the working model
A rule formats a cell only when two things are true: the cell is inside the range, and the condition is true for it. For custom formulas, the range's top-left cell also defines how the formula's references are read. Choose an open-ended range for growing tables, start it below the header, match the formula's row number to the range's first row, and add extra ranges only for blocks that truly share the same rule.
Exercise
A sheet has headers in row 1 and data in rows 2 to 50. You apply the custom formula =$B2>100 to the range A1:D50, and the highlighting appears one row higher than the values that exceed 100. What is wrong, and what two changes would make the rule both correct and ready for new rows?
Show answer
The range starts at row 1, so Sheets reads the formula as written for A1, and $B2 points one row below the cell being formatted. Change the range to start at row 2 so it matches the formula's row number. To cover rows added later, make the range open-ended: A2:D.
Exercise
You want one rule to turn negative numbers red in B2:B13 and D2:D13, but not in column C between them. How do you set this up, and what built-in condition would you use?
Show answer
Put both blocks in the rule's range, either by clicking Add another range or by typing B2:B13, D2:D13. Choose the built-in condition Less than and enter 0 as the value, then choose a red font or fill. Column C is not in the range, so it is never formatted.