How to Return a Value If Cell Color Is Red in Google Sheets

Table of Contents

Table of Contents

In Google Sheets, you can return a specific value in one column based on the background color of a cell in another column, such as flagging a row if a cell is red. While this seems simple, itโ€™s not something standard formulas like IF or COUNTIF can handle. This is because visual formatting (like background color) is not accessible via formulas.

In this article, weโ€™ll walk through different methods to detect if a cell is red and return a corresponding value, ranging from custom Apps Script to third-party add-ons. These techniques are perfect for workflows where colors represent status, urgency, or errors, and you need to automate responses based on visual cues in your sheet.

Key Takeaways

Steps to check for red-colored cells in Google Sheets using the markRedStatuses() Apps Script:

โžค Start with a dataset in cells A1:B11, where column B contains status values like โ€œDelayed,โ€ some of which are colored red.
โžค Open the script editor by navigating to Extensions >> Apps Script.
โžค Paste the following script in the editor:

function markRedStatuses() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var range = sheet.getRange("B2:B11"); // Adjust this if needed
  var colors = range.getBackgrounds();
  var output = [];
  for (var i = 0; i < colors.length; i++) {
    if (colors[i][0].toLowerCase() === '#ff0000') {
      output.push(['Attention Needed']);
    } else {
      output.push(['']);
    }
  }
  sheet.getRange("C2:C11").setValues(output);
}

โžค Save the script, then run it from the toolbar to execute it.
โžค The script checks if each cell in B2:B11 has a red background. If it does, it writes โ€œAttention Neededโ€ in the corresponding row of column C.

overview image


1

Use Apps Script to Check If Cell Color is Red and Return a Value

When you want to perform an action based on cell color in Google Sheets, formulas alone wonโ€™t work because they can’t read cell formatting like color. Instead, you can use Google Apps Script to create a custom function that checks if a cellโ€™s background color is red and returns a specific value, such as “Attention Needed,” in another column. This method is dynamic and updates when you run the script, making it useful for tracking statuses like delayed tasks.

This is the dataset we will be using to demonstrate the methods:

Use Apps Script to Check If Cell Color is Red and Return a Value

Steps:

โžค Open your Google Sheet with the dataset (Tasks in column A and Status in column B, where โ€œDelayedโ€ cells are colored red).
โžค Go to Extensions >> Apps Script to open the script editor.

Use Apps Script to Check If Cell Color is Red and Return a Value

โžค Paste this function in Apps Script:

function markRedStatuses() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var range = sheet.getRange("B2:B11"); // Adjust this if needed
  var colors = range.getBackgrounds();
  var output = [];
  for (var i = 0; i < colors.length; i++) {
    if (colors[i][0].toLowerCase() === '#ff0000') {
      output.push(['Attention Needed']);
    } else {
      output.push(['']);
    }
  }
  // Write to column C (next to B2:B11)
  sheet.getRange("C2:C11").setValues(output);
}

Use Apps Script to Check If Cell Color is Red and Return a Value

โžค Save the script by clicking on the floppy disk icon, then return to your sheet.

Use Apps Script to Check If Cell Color is Red and Return a Value

โžค Click on Run.

โžค Go back to the sheet. The script will return “Attention Needed” for all rows where the status cell background is red.

Use Apps Script to Check If Cell Color is Red and Return a Value

โžค This method is ideal when you want to base conditional outputs on cell color, something not possible with native formulas alone.


2

Implement Conditional Formatting and Helper Column for Color Detection

Because Google Sheets formulas cannot directly detect cell background colors, you can mimic this by using Conditional Formatting rules to highlight cells with a red color based on their content or conditions. Then, add a helper column that uses a formula to check the same condition and return a specific value. This method leverages the logic behind coloring, rather than reading the color itself, to automate results without scripts.

We have removed the red colours from our dataset for this method as we will add them again through conditional formatting.

Implement Conditional Formatting and Helper Column for Color Detection

Steps:

โžค Select the range where you want to apply the red color formatting (for example, B2:B11).
โžค Go to Format  >> Conditional formatting.

Implement Conditional Formatting and Helper Column for Color Detection

โžค In the Conditional format rules sidebar, under “Format cells if,” select Custom formula is.
โžค Enter the formula that matches your criteria for red cells, for example:

=B2=”Delayed”

โžค Choose a red fill color and click Done. The cells with the value โ€œDelayedโ€ will now be colored red.

Implement Conditional Formatting and Helper Column for Color Detection

โžค In the adjacent helper column (for example, C2), enter this formula to return a specific value when the condition is met:

=IF(B2=”Delayed”, “Check Status”, “”)

Implement Conditional Formatting and Helper Column for Color Detection

Explanation
โžง Since formulas cannot detect colors, the helper column duplicates this logic to return a value if the cell meets the condition for red formatting.
โžง IF(A2="Delayed", "Check Status", "") checks if the cell contains "Delayed" and returns "Check Status" if true, or leaves it blank otherwise.
โžง Adjust the conditional formatting formula and the IF condition to fit your specific criteria and dataset.

โžค Press Enter and drag the formula down alongside your data range. The helper column will now show โ€œCheck Statusโ€ next to any cell with โ€œDelayed,โ€ matching your red color formatting.

Implement Conditional Formatting and Helper Column for Color Detection


3

Use the “Function by Color” Add-on to Return Values Based on Cell Color

If you want to perform calculations or return specific text based on a cellโ€™s background color without using Apps Script, the Function by Color add-on is a great option. It allows you to apply custom functions that recognize cell fill color directly in Google Sheets formulas.

This is the dataset we will be using for this method:

Use the "Function by Color" Add-on to Return Values Based on Cell Color

Steps:

โžค Open your Google Sheet.
โžค Go to Extensions >> Add-ons >> Get add-ons.

Use the "Function by Color" Add-on to Return Values Based on Cell Color

โžค In the Google Workspace Marketplace, search for Function by Color.

Use the "Function by Color" Add-on to Return Values Based on Cell Color

โžค Click Install, and follow the prompts to authorize the add-on.
โžค After installation, go to Extensions >> Function by Color >> Start to open the sidebar.

Use the "Function by Color" Add-on to Return Values Based on Cell Color

โžค In the sidebar, select the range where red-colored cells are located (e.g., B2:B11).

โžค Click on the color dropper and select the cell that contains the red color.

โžค Select COUNTA (Text) from the โ€˜Use Functionโ€™ field.
โžค Select cells C2:C11 in the โ€˜Paste results inโ€™ field.
โžค Select each row in the โ€˜Calculate inโ€™ field.
โžค Uncheck โ€˜Fill results with your pattern colorsโ€™.

โžค Click on Insert Function.

The cells that are red colored will now have the number 1 next to them. This is very useful in a larger dataset.

โžค Whenever you change cell colors, go to Extensions >> Function by Color >> Refresh results to update the formula outputs.


Practice Resources

Get our practice workbook or necessary files that we have worked with to prepare this article.

Return a Value If Cell Color Is Red in Google Sheets [Make a Copy]


Frequently Asked Questions

Can Google Sheets detect cell background color using a formula?

No, Google Sheets formulas cannot detect cell background colors. You need to use Google Apps Script or add-ons for color-based logic and automation.

How do I return a value based on cell color in Google Sheets?

You canโ€™t use formulas for this. Instead, use Apps Script to check the cell color, then return a value in another column based on that condition.

Is there a way to filter by cell color in Google Sheets?

Yes, use the filter feature and select โ€œFilter by color.โ€ However, this works manually and doesnโ€™t support dynamic filtering via formulas.

Whatโ€™s the best alternative to formulas for color-based conditions?

The best alternative is using a helper column with specific text values and applying conditional formatting for color. This allows formula compatibility and better control.


Wrapping Up

While Google Sheets formulas can’t directly evaluate cell colors, you can still create color-based logic using Apps Script or by redesigning your sheet with helper columns and conditional formatting. Whether you’re flagging delayed tasks or highlighting key values, combining visual cues with script automation or structured data makes your spreadsheets both functional and user-friendly. By understanding the limitations and leveraging the right tools, you can efficiently return specific values based on color and enhance the clarity of your reports or dashboards.

Facebook
X
LinkedIn
WhatsApp
Picture of Mohammed Shafin Arshad

Mohammed Shafin Arshad

Mohammed Shafin Arshad is a Computer Science student and cybersecurity enthusiast in Malaysia with 6 years of Excel and Google Sheets experience. He specializes in VBA, macro automation, and SaaS-focused workflow guides. His background includes university data science projects, and he enjoys using macros to solve complex spreadsheet problems.
We will be happy to hear your thoughts

      Leave a reply


      Excel Insider
      Logo