Using INDIRECT in Conditional Formatting in Google Sheets

Published on

The INDIRECT function is essential when creating a conditional formatting rule that references cells across different sheet tabs in Google Sheets.

In other words, you cannot directly refer to a cell in another sheet within the custom formula field for conditional formatting.

For example, let’s say you have two sheets: one named “Find Group” and the other “Student Group.”

If your active sheet is “Find Group,” you would normally refer to cell A1 in “Student Group” like this:

='Student Group'!$A$1

However, you cannot use this reference directly in the custom formula field for conditional formatting. Instead, you need to use the INDIRECT function, like this:

=INDIRECT("Student Group!A1")

Let me give you a real-life example.

Example

I am confident that you will appreciate the following example, where I will use the INDIRECT function in conditional formatting.

I have a dataset containing student names in a sheet named “Student Group,” categorized under different groups. There are four groups named RED, BLUE, GREEN, and YELLOW in cells B1:E1. Under each header, the student names belonging to those groups are listed.

Sample Data - INDIRECT Function in Conditional Formatting
Image #1

Assume these students have participated in various competitions during a school annual day event.

I have the names of the winners in another sheet in column A, without the associated group names. In that sheet, named “Find Group,” I want to highlight the cell with the group color when I enter the name of any winner from any group.

Highlighting Names Based on Assigned Groups
Image #2

I will explain how we can achieve this, and along the way, you will also learn the role and use of the INDIRECT function in conditional formatting.

INDIRECT in Custom Formula Rules for Conditional Formatting

Let’s review the conditional formatting rules for the example above.

We will apply conditional formatting to the range A2:A in the “Find Group” sheet (refer to screenshot #2). However, the reference data is located in the range B2:E in the “Student Group” sheet (refer to screenshot #1).

Since there are four groups in four columns, we need four custom formulas to achieve this.

=XMATCH(A2, INDIRECT("'Student Group'!B:B")) // red
=XMATCH(A2, INDIRECT("'Student Group'!C:C")) // blue
=XMATCH(A2, INDIRECT("'Student Group'!D:D")) // yellow
=XMATCH(A2, INDIRECT("'Student Group'!E:E")) // green

These XMATCH formulas check if the name in cell A2 matches any names in columns B, C, D, and E of the “Student Group” sheet and return either a number or #N/A.

Wherever the formulas return a number, the corresponding cells in column A of the “Find Group” sheet will be highlighted.

Using INDIRECT Formulas for Conditional Formatting

Here’s how to apply the above rules and highlight student names based on their group.

Ensure that cell A2 is the active cell in the “Find Group” sheet. Then, click Format > Conditional formatting.

Under “Apply to range,” enter A2:A or A2:A100 (depending on your preferred range).

In the “Format cells if…” drop-down menu, select Custom formula is and copy-paste the first formula.

Under “Formatting style,” select the color Red.

Apply INDIRECT-Based Custom Rules in Conditional Formatting
Image #3

Click “Add another rule,” then copy and paste the second formula. Change the color to Blue. Repeat this process for the other two formulas, setting their corresponding colors.

To test if all the formulas work as expected, enter the name of a student from any group in the A2:A range of the “Find Group” sheet. The cell should be highlighted according to the student’s group color.

Note: Avoid copying and pasting names, as this may remove the conditional formatting rules you’ve set.

Here is my sample Google Sheets file.

Sample Sheet

Resources

Here are two more tutorials where I have used the INDIRECT function in conditional formatting in Google Sheets:

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Compare Two Tables for Differences in Excel

To compare two tables with similar data for differences, you can use the XLOOKUP...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

More like this

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

8 COMMENTS

  1. I am trying to shade some cells based on the numerical value in another cell.

    I have have tried many options, but it does not seem to work in Google Sheets.

    E.g., in cell A1 I put the value 6. So then I want this to shade the cell range A6:C6.

    …how simple is that, but I cannot achieve it.

    I have tried using the Indirect and Index functions in the conditional formatting, but it doesn’t work.

    Any ideas, please?

    • Hi, Giles,

      This formula will highlight A1:C1 if A1 is 1, A2:C2 if A1 is 2, and so on.

      =INDEX(
      LET(control_cell,A1,range,INDIRECT("A"&$A$1&":C"&$A$1),
      MATCH(CELL("address",control_cell),ADDRESS(ROW(range),COLUMN(range)),0))
      )

      Apply to range: A1:C1000.

  2. Goal:- Have the cell change color once the original number is replaced with a new number.

    Thanks for any potential help!

  3. I tried using your formula, but it does not apply the formatting correctly. Instead of formatting only the cells in the range that match the criteria, it formats the entire range if one cell matches. How do I get it to stop doing that?

  4. I can use a named range to refer to a cell in another sheet, right? I have tried this in the following formula =IF($A80,IF(AND(($M8+Last_contact_followup<=TODAY()),S8"Won"),TRUE,FALSE),"") and I get an error message if I put this formula into Conditional formatting / Custom formula in a Google Sheet.

    The error comes from the named range “Last_contact_followup” and I have no idea why? This works in Excel but not in Google Sheets. Where do I get wrong?

    • Hi, Thomas,

      I don’t know what you are trying to achieve. So it’s tough for me to correct the formula.

      I am sure that the formula is not coded correctly. For example, take a look at the AND use. I guess there is a small typo in your formula. It must be as below.

      =AND($M8+Last_contact_followup<=TODAY(),S8="Won")

      This part will work correctly. It would return TRUE or FALSE. But in conditional formatting use Indirect with the named ranges as below.

      =AND($M8+indirect("Last_contact_followup")<=TODAY(),S8="Won")

      It will highlight the "Apply to range" cell (see the conditional formatting panel) to your set color if the output is TRUE, else blank. I don't know why you are using the IF statement. It may not be required in conditional formatting.

      Best,

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.