Sub topic 10
Using data from another sheet with INDIRECT
This chapter shows how to make a conditional formatting rule depend on values stored on a different sheet. It assumes you can already write a custom formula rule, you know the difference between $A2 and A2, and you have used COUNTIF. If those are unfamiliar, review the chapters on custom formulas and cell references first.
Why a direct reference fails
A common setup keeps a lookup list on its own sheet. An example is a sheet named Lists that holds approved vendor names in column A. You want the vendor column on your Orders sheet to highlight any name found in that list.
The obvious formula points straight at the other sheet:
=COUNTIF(Lists!A:A,$A2)>0Google Sheets rejects this in a conditional formatting rule. The rule editor shows an error such as "Conditional format rules cannot reference other sheets directly" and will not save the rule. The same formula works in a normal cell. The restriction applies only to the rule editor.
The workaround is INDIRECT. It turns a piece of text into a reference at the moment the rule is evaluated. The rule editor only sees a text string, so it has nothing to reject.
How INDIRECT works
INDIRECT(ref_text) takes a string that describes a cell or range and returns that range. These two formulas return the same result:
=SUM(Lists!A1:A10)=SUM(INDIRECT("Lists!A1:A10"))The text is ordinary text, so you can build it with &. This lets a cell hold the sheet name:
=SUM(INDIRECT("'"&B1&"'!A1:A10"))In a conditional formatting rule, INDIRECT is the bridge. The rule editor accepts the formula because the other sheet appears only inside a string. When Sheets evaluates the rule for each cell, it converts the string to a real range and runs the rest of the formula.
The standard pattern
The spine's example applies to A2:A100 on the Orders sheet:
=COUNTIF(INDIRECT("Lists!A:A"),$A2)>0Read it from the inside out:
INDIRECT("Lists!A:A")returns the whole of column A on theListssheet.COUNTIF(..., $A2)counts how many times the current row's value appears in that column.>0turns the count intoTRUEorFALSE. ATRUEresult applies the format.
The $A2 reference follows the same anchoring rules as any custom formula rule. The column is locked and the row is relative. Sheets evaluates the formula as if it were typed into the first cell of the range, then shifts relative parts for every other cell.
The diagram shows how one cell is evaluated.
Setting it up step by step
- Create a sheet named
Listsand type your approved values inA2:A50. - Go to the
Orderssheet and selectA2:A100. - Choose Format, then Conditional formatting.
- Under Format rules, set the condition to Custom formula is.
- Enter
=COUNTIF(INDIRECT("Lists!A:A"),$A2)>0. - Pick a fill color and select Done.
Typing a vendor name that appears in Lists!A:A now shades the cell. Typing a name that is not on the list leaves it plain. You can also invert the test to flag unapproved values:
=COUNTIF(INDIRECT("Lists!A:A"),$A2)=0This version has a trap. Empty cells in A2:A100 also have a count of zero, so every blank row lights up. The fix is covered in the edge cases below.
Quoting sheet names
The text inside INDIRECT follows the same rules as a reference typed into a cell. A sheet name with spaces, punctuation, or a leading digit must be wrapped in single quotes. Those quotes live inside the double-quoted string.
| Sheet name | Text to pass to INDIRECT |
|---|---|
| `Lists` | `"Lists!A:A"` |
| `Approved Vendors` | `"'Approved Vendors'!A:A"` |
| `2026 Data` | `"'2026 Data'!A:A"` |
| `Q1-Report` | `"'Q1-Report'!A:A"` |
Quoting a simple name such as 'Lists'!A:A is also valid, so you can always add the single quotes. If a sheet name itself contains a single quote, double it inside the text. Renaming such a sheet to remove the apostrophe is usually easier.
Choosing the sheet name from a cell
Instead of hard-coding the name, you can read it from a cell on the same sheet. Suppose Orders!H1 holds the text Approved Vendors:
=COUNTIF(INDIRECT("'"&$H$1&"'!A:A"),$A2)>0Anchor the cell with $H$1 on both parts so the sheet name does not shift as the rule moves down the range. Changing H1 then changes which list the rule checks, with no need to edit the rule.
If you want a different sheet name for each region, put the name in a helper column and use a mixed reference such as $G2. Each row then points at its own sheet.
Matching multiple columns
To compare against a two-column list, check a specific column in each sheet. This rule highlights rows on Orders where both the vendor in column A and the region in column B appear together on one row of Lists:
=SUMPRODUCT((INDIRECT("Lists!A2:A50")=$A2)*(INDIRECT("Lists!B2:B50")=$B2))>0Each INDIRECT call returns a bounded range. The comparison produces an array of TRUE and FALSE values, and multiplying two arrays gives 1 only where both conditions hold. SUMPRODUCT adds those ones. Both ranges must have the same size or the formula returns an error.
Edge cases and gotchas
The string does not follow renames or moves
A normal reference such as Lists!A:A updates automatically if you rename the sheet. The text "Lists!A:A" does not. If someone renames Lists to Vendors, INDIRECT returns a #REF! error. In a conditional formatting rule an error is treated as FALSE, so the rule fails silently and nothing is highlighted. After you rename a sheet, edit every INDIRECT rule that mentions it.
Inserting or deleting rows and columns on the other sheet has the same effect. A fixed string such as "Lists!A2:A50" will not grow or shrink with the data. Using the whole column A:A avoids this, at a small cost in speed.
Blank cells
When $A2 is empty, COUNTIF compares against an empty criterion. This can match blank cells in the list or behave inconsistently. Guard against it explicitly:
=AND($A2<>"",COUNTIF(INDIRECT("Lists!A:A"),$A2)=0)This is the safer form of the "not on the list" rule. It formats a cell only when the cell holds a value and the value is missing from the list.
Wildcards and operators in values
COUNTIF treats *, ?, and ~ in the criterion as wildcards. It also reads values that begin with >, <, or = as comparison operators. A vendor named Smith*Co can therefore match more than you intend. When values might contain these characters, use an exact comparison:
=SUMPRODUCT(--(INDIRECT("Lists!A2:A50")=$A2))>0The -- converts TRUE and FALSE to 1 and 0. Comparisons in Sheets are not case-sensitive, so acme and ACME still match.
Numbers stored as text
If the list holds 1001 as text and the order column holds 1001 as a number, they do not match. The usual cause is data pasted from another system. Make both columns the same type, or compare text versions with TEXT or &"" on both sides.
Volatility and performance
INDIRECT is volatile. Sheets recalculates it whenever anything on the sheet changes, because it cannot tell which cells the text refers to. A rule over A2:A100 that scans a whole column is fine. A rule covering tens of thousands of rows, each scanning a large column, can make editing sluggish. To keep it fast:
- Use bounded ranges such as
"Lists!A2:A500"when the list size is predictable. - Apply the rule to the smallest range that needs it.
- Avoid stacking many
INDIRECTrules over the same large range.
Named ranges
INDIRECT also accepts the name of a named range as text. If ApprovedVendors is a named range pointing at Lists!A2:A50, then INDIRECT("ApprovedVendors") returns that range. This gives you a layer of indirection. If the list moves, you update the named range once instead of editing each rule.
=COUNTIF(INDIRECT("ApprovedVendors"),$A2)>0Other workbooks
INDIRECT cannot reach a different spreadsheet file. If you need values from another file, bring them in with IMPORTRANGE on a helper sheet of your own workbook, then point the rule at that sheet with INDIRECT.
A complete example
Here is a combined rule that checks several conditions. On Orders, rows A2:F100 hold an order with the vendor in column A and the status in column C. The Lists sheet holds blocked vendors in column A. You want to highlight the whole row in red when the vendor is blocked and the order is not yet Done.
Apply the rule to A2:F100 with this formula:
=AND($A2<>"",$C2<>"Done",COUNTIF(INDIRECT("Lists!A:A"),$A2)>0)Check each part:
$A2<>""skips blank rows.$C2<>"Done"ignores finished orders.COUNTIF(INDIRECT(...),$A2)>0tests the blocked list.- The
$before each column letter keeps the test pointed at columns A and C for every cell inA2:F100, so the whole row changes together.
To confirm it works, type a blocked vendor name into a new row and set the status to something other than Done. Then change the status to Done and watch the row return to normal.
Quick diagnosis checklist
When an INDIRECT rule does nothing, work through these checks in order:
- Paste the string argument into a normal cell as
=INDIRECT("Lists!A:A")and see whether it returns an error. A#REF!points to a wrong sheet name or missing quotes. - Confirm the rule's Apply to range matches where you expect the format to appear.
- Check the anchoring. A missing
$can shift the lookup to the wrong cell. - Compare data types between the two sheets.
- Look for a higher rule in the list that applies its own fill and takes precedence.
Exercises
Exercise
Why does the rule =COUNTIF(Lists!A:A,$A2)>0 fail in the conditional formatting editor, and what is the minimal change that makes it work?
Show answer
The conditional formatting editor does not allow direct references to other sheets. Wrapping the reference in INDIRECT as text fixes it: =COUNTIF(INDIRECT("Lists!A:A"),$A2)>0. The sheet reference is then only a string when the rule is saved and becomes a real range when evaluated.
Exercise
Your sheet is named Approved Vendors and you want to highlight values in A2:A100 that are not in its column A. The rule should skip blank cells. Write the custom formula.
Show answer
=AND($A2<>"",COUNTIF(INDIRECT("'Approved Vendors'!A:A"),$A2)=0). The single quotes inside the string are required because the sheet name contains a space. The $A2<>"" test stops blank rows from being highlighted.
Exercise
A teammate renames the Lists sheet to Vendors. Your INDIRECT rule stops highlighting anything, and no error message appears. Explain why, and give two ways to make the setup easier to maintain.
Show answer
The sheet name is stored as text inside the INDIRECT call, so Sheets does not update it on rename. INDIRECT returns #REF!, and a rule that errors is treated as FALSE, so nothing is formatted. You can edit the rule to use the new name, or read the sheet name from a cell (INDIRECT("'"&$H$1&"'!A:A")) so only that cell needs updating. A named range such as INDIRECT("ApprovedVendors") also works, because you update the named range once instead of each rule.