Sub topic 8
How rule order decides which format wins
This chapter assumes you can open the conditional formatting sidebar, apply a single color rule, and write a basic custom formula rule with $ anchors. If a cell matches more than one rule, the order of the rules in the sidebar decides which formatting you see. You will learn how that order works, how to design rule sets that don't depend on it by accident, and how to read a conflict when a cell shows the wrong color.
Why order matters at all
A single rule never conflicts with anything. Conflicts start when two or more rules cover the same cell and both evaluate to true. Consider a task tracker in A2:E100:
- Column C holds the status: Done, In progress, or Blocked.
- Column D holds the due date.
Suppose you want three signals:
- Overdue unfinished tasks get a red fill.
- Blocked tasks get an orange fill.
- Done tasks get a green fill.
A task can be both Blocked and overdue. Both rules are true for that row, but a cell can only show one fill. Something has to decide which one is used, and in Google Sheets that something is the position of each rule in the sidebar list.
The core rule: top of the list wins
Google Sheets keeps all conditional formatting rules for a sheet in one ordered list. You see them as cards in the sidebar under Format > Conditional formatting.
Sheets evaluates the rules from the top card to the bottom card. For each cell, the first rule that is true for that cell supplies the formatting. Rules below it that are also true have no effect on that cell.
This differs from some other spreadsheet tools. In Excel, rules that don't conflict can combine. For example, one rule can add bold while another adds a fill. In Google Sheets you should plan on a cell showing the formatting of one rule only. If you want bold text and a red fill together, put both in the same rule.
A few details follow from this model:
- The order applies per cell, not per rule. Two rules with different ranges only compete on the cells where their ranges overlap.
- A rule that is false for a cell is skipped for that cell. The next rule down still gets its turn.
- A rule that formats nothing visible, such as one whose fill is left on "none" and whose text style is unchanged, can still win. It then blocks the rules below it from showing.
Walking through the tracker example
Here are the three rules for the range A2:E100, with each custom formula:
=AND($D2<TODAY(),$C2<>"Done")=$C2="Blocked"=$C2="Done"Call them Overdue, Blocked, and Done. The formulas are written from the point of view of the first cell in the range, A2, and the $ anchors keep each formula pointed at columns C and D as it is applied across the row.
Take a row with status Blocked and a due date last week. The Overdue rule is true and the Blocked rule is also true. The Done rule is false. The result depends only on which of the first two is higher in the list:
| Order in the sidebar (top to bottom) | Blocked and overdue row shows | Done row shows |
|---|---|---|
| Overdue, Blocked, Done | Red (Overdue) | Green |
| Blocked, Overdue, Done | Orange (Blocked) | Green |
| Done, Blocked, Overdue | Orange (Blocked) | Green |
A Done row with a past due date is false for the Overdue rule because of the $C2<>"Done" test, so it is unaffected by the order of the other two. That test is an example of making a rule exclude a case itself, instead of relying on position. The next sections come back to this idea.
How evaluation proceeds
The following diagram shows what Sheets does for one cell. It repeats this for every cell in the ranges that have rules.
The last box matters. If no rule is true, the cell shows whatever manual formatting you gave it, such as a static fill from the toolbar. When a rule is true, its fill and text style take over the properties it sets. Static formatting underneath only shows through for properties the winning rule leaves unset, or when no rule applies.
Reordering rules
To change priority, open the sidebar and drag a rule card by the handle at its left edge, the grip of six dots. Move it up to give it higher priority or down to lower it. The change takes effect immediately and the sheet recolors.
Follow this routine when you add a new rule to a sheet that already has several:
- Click any cell in the formatted area to open the sidebar and see the list of rules.
- Add the new rule. New rules are added at the top of the list, so a new rule starts with the highest priority.
- Decide where the new rule belongs. If it should be an exception that beats existing rules, leave it at the top. If it is a fallback, drag it down.
- Check a cell that should match both the new rule and an older one, and confirm the color you expected.
The step 2 detail is the most common source of surprises. A rule added later outranks all earlier rules, even if you meant it as a low-priority default.
Exceptions above, defaults below
A reliable design is to order rules from the most exceptional to the most general:
- Rules for rare, high-importance cases at the top (overdue, errors, blocked).
- Rules for ordinary states in the middle (in progress, done).
- Broad catch-all or banding rules at the bottom.
For example, alternating row shading from the earlier chapters uses this formula:
=MOD(ROW(),2)=0That rule is true on every even row, so if you place it above the status rules it will hide them on half the rows. Put banding at the bottom and it only shows on rows where no status rule fired. For rows with a status color, the status wins, and the banding appears only on the remaining rows.
Designing rules that don't depend on order
Order-dependent rule sets work, but they break easily. Someone adds a rule, drags a card, or copies rules to another sheet, and colors change without any formula changing. You can reduce that risk by making the formulas mutually exclusive, so that at most one rule can be true for any cell.
Rewrite the tracker rules so each one states its own conditions:
=AND($D2<TODAY(),$C2<>"Done")=AND($C2="Blocked",NOT($D2<TODAY()))=$C2="Done"Now a Blocked and overdue row is true only for the first rule. A Blocked row that is not overdue is true only for the second. The three rules can be in any order and the result is the same.
This has costs. The formulas get longer and each new rule may need edits to the others. A rule of thumb:
- Use order when the exceptions are few and the list is short. Add a short note to yourself in the sheet, because the sidebar doesn't store comments.
- Use mutually exclusive formulas when the sheet is shared, long-lived, or has more than three or four overlapping rules.
- Mix the approaches when it is convenient. Use exclusion for the cases that matter most and order for the rest.
Color scales and single color rules together
A color scale is a rule too, and it takes its place in the same list. If a color scale sits above a single color rule and both cover the same cell, the color scale wins on every numeric cell it formats. This is a typical cause of "my highlight rule does nothing" on columns that also have a gradient.
You can use this on purpose. Say B2:B100 holds sales figures shaded with a color scale from white to green, and you want zero values to be gray instead of the palest green. Add a custom formula rule on the same range and put it above the color scale:
=AND(ISNUMBER(B2),B2=0)Set its fill to light gray. Cells equal to 0 match this rule first and use the gray. All other numeric cells fall through to the color scale beneath it.
The ISNUMBER test matters because a blank cell compares as equal to 0. Without it, empty cells would turn gray too.
Overlapping ranges
Rules in the same sheet share one list even when their ranges differ. That makes it possible for a rule you wrote months ago on a small range to affect a newer rule on a larger range.
Suppose rule 1 applies to A2:A100 and rule 2 applies to A2:F100. In column A, both rules can be true. Order decides between them. In columns B to F, only rule 2 covers those cells, so rule 1 has no influence there. When you read the list, check the range printed on each card, not only the formula.
Two practical habits help:
- When you add a rule on a larger range, scan the sidebar for existing rules whose ranges overlap it.
- When you split a range, for example to treat the header row differently, make sure the header rule sits at the top. Otherwise the broad rule still colors those cells.
Order and copying
When you copy cells with Paste special > Conditional formatting only, the copied rules are added to the destination. They go into the destination's list and can end up above or below the rules already there. After pasting, open the sidebar on the destination and check the order. Copying a rule does not preserve its relative position against rules that were already in the target sheet.
Details of copying and deleting are covered in the next chapter. For now, treat any paste of formatting as an event that may have changed the order.
Troubleshooting order problems
Symptoms and likely causes:
| Symptom | Likely cause | Fix |
|---|---|---|
| A rule's formula is correct but nothing changes in some cells | A rule above it is true for those cells | Drag the rule up, or make the rule above it more specific |
| A color scale does not show on some numbers | A single color rule above it is true there | Move the scale up, or narrow the single color rule |
| Colors changed after you added a rule | New rules are added at the top | Drag the new rule to the intended position |
| Banding hides status colors | The banding rule is above the status rules | Move banding to the bottom |
| A rule formats cells you didn't expect | An overlapping range on another card | Check each card's range, and narrow it |
A useful test is to temporarily turn a suspect rule into the top card and see whether the cells change. If they do, order was the problem. If they don't, the formula or range is the problem, and the earlier chapters on references cover how to check those.
Summary of the model
- All rules for a sheet sit in one ordered list.
- For each cell, the first true rule from the top supplies the format. Later true rules are ignored for that cell.
- New rules go to the top. Drag a card's handle to change its priority.
- Order a list from exceptions down to defaults, or write exclusive formulas so order doesn't matter.
- Color scales take part in the same ordering.
Exercise
A sheet has two rules on B2:B50, in this order from the top: (1) custom formula =B2>0 with a yellow fill, and (2) custom formula =B2>100 with a red fill. A cell contains 250. What color does it show, and what is the smallest change that makes values over 100 red?
Show answer
The cell shows yellow. Both rules are true for 250, and rule 1 is higher in the list, so its format wins and rule 2 is ignored for that cell. The smallest change is to drag the red rule above the yellow rule. Values over 100 then match the red rule first and show red. Values from 1 to 100 are false for the red rule, so they fall through to yellow.
Exercise
You have a color scale on C2:C100 and want to show any cell that contains text (such as "n/a") in italic gray, without changing how numbers are shaded. Write a custom formula for the new rule and say where it belongs in the list.
Show answer
Use =ISTEXT(C2) on the range C2:C100 with gray italic text. It can sit above or below the color scale, because a color scale only formats numbers and ISTEXT is false for numbers. Placing it at the top is the safer choice, since it then wins on any text cell no matter how the scale treats it, and it never competes with the scale on numeric cells.