Can Google Sheets Count Colored Cells?

Jacob Jul 28, 2026

Ever found yourself poring over Google Sheets, wondering if there's a quick way to count cells based on their color? While Google Sheets doesn't have a built-in function for this, there are indeed workarounds to achieve this. Let's delve into the world of Google Sheets' conditional formatting and scripts to explore how to count colored cells.

3 ways to count colored cells in Google Sheets (including a free script)
3 ways to count colored cells in Google Sheets (including a free script)

Before we dive in, it's crucial to understand that Google Sheets doesn't natively support counting cells based on their fill color. However, we can use a combination of conditional formatting, data validation, and even Google Apps Script to accomplish this task. So, let's get started!

How to count or sum cells based on cell color in Google sheet?
How to count or sum cells based on cell color in Google sheet?

Using Conditional Formatting and Data Validation

This method involves using conditional formatting to mark cells based on their color and then using data validation to count these marked cells. Here's how you can do it:

Count the Colors in Google Sheets - Teacher Tech with Alice Keeler
Count the Colors in Google Sheets - Teacher Tech with Alice Keeler

First, apply conditional formatting to mark cells based on their color. Select the range of cells, click on 'Format' in the menu, then 'Conditional formatting'. Under the 'Format cells if...' dropdown, choose 'Custom formula is', and enter the formula to match the color you're interested in. For example, to match red cells, you might use '=A1<>"".

Marking Cells Based on Color

Google Sheets - Sum or Count Values Based on Cell Color [Improved]
Google Sheets - Sum or Count Values Based on Cell Color [Improved]

In the formula, 'A1<>""' checks if the cell is not empty. You'll need to adjust this based on the color you're targeting. Once you've set the formula, choose the formatting style (like a fill color or a border), and click 'Done'.

Next, use data validation to count these marked cells. Select the range of cells, click on 'Data' in the menu, then 'Data validation'. Under 'Criteria', choose 'Custom formula is', and enter the same formula you used for conditional formatting. Click 'Save'.

Counting Marked Cells

the words count or sum cell's based on cell color in excel are shown
the words count or sum cell's based on cell color in excel are shown

Now, when you select the range of cells, Google Sheets will display the count of cells that match the criteria in the top-left corner. This count updates automatically as you add or remove cells that match the criteria.

Using Google Apps Script

If you're comfortable with a bit of coding, you can use Google Apps Script to create a custom function that counts cells based on their color. Here's a simple script to get you started:

How to Change Your Google Sheets Theme Color
How to Change Your Google Sheets Theme Color

In your Google Sheets document, click on 'Extensions' in the menu, then 'Apps Script'. Delete any code in the 'Code.gs' file, and paste the following:

```javascript function COUNTCOLOREDCELLS(range, color) { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getActiveSheet(); var cells = sheet.getRange(range).getCells(); var count = 0; for (var i = 0; i < cells.length; i++) { if (cells[i].getBackground() == color) { count++; } } return count; } ```

Creating the Custom Function

How to hide cells in Google Sheets
How to hide cells in Google Sheets
An easy to follow, quick script for getting the hex code colors for a Google Sheet cell
An easy to follow, quick script for getting the hex code colors for a Google Sheet cell
Google Sheets - Sum or Count Values Based on Cell Color
Google Sheets - Sum or Count Values Based on Cell Color
Count & sum cells by color in Google Sheets
Count & sum cells by color in Google Sheets
6 Crazy Google Sheets Formulas You Should Know
6 Crazy Google Sheets Formulas You Should Know
How to add a Calendar into a cell in Google Sheets #googlesheets #tutorial #spreadsheet
How to add a Calendar into a cell in Google Sheets #googlesheets #tutorial #spreadsheet
CHECK the Conditional Formatting - Teacher Tech with Alice Keeler
CHECK the Conditional Formatting - Teacher Tech with Alice Keeler
How to Change Cell Color in Google Sheets easily
How to Change Cell Color in Google Sheets easily
Google Sheets: Alternate Colors - Teacher Tech with Alice Keeler
Google Sheets: Alternate Colors - Teacher Tech with Alice Keeler
Google Sheets For Beginners - Lock Top Row
Google Sheets For Beginners - Lock Top Row
How to Calculate Running Total in Google Sheets
How to Calculate Running Total in Google Sheets
How to Highlight Duplicates in Google Sheets
How to Highlight Duplicates in Google Sheets
30+ Essential Google Sheets Functions
30+ Essential Google Sheets Functions
How to Count Colored Cells in Excel (4 Simple Ways) - ExcelDemy
How to Count Colored Cells in Excel (4 Simple Ways) - ExcelDemy
Google Sheets Lessons - Using the Sum Function Colored Candies
Google Sheets Lessons - Using the Sum Function Colored Candies
How to Count Cells with Specific Text in Google Sheets
How to Count Cells with Specific Text in Google Sheets
Color Alternate Rows In Google Sheets.
Color Alternate Rows In Google Sheets.
5 Google Sheets Essentials - Teacher Tech with Alice Keeler
5 Google Sheets Essentials - Teacher Tech with Alice Keeler

This script defines a function called 'COUNTCOLOREDCELLS' that takes a range and a color as arguments. It loops through each cell in the range, checks its background color, and increments a counter if the color matches.

To use this function, select the range of cells, then click on the cell where you want the count to display. Type '=COUNTCOLOREDCELLS(', then select the range of cells, a comma, the color in hexadecimal format (like '#FF0000' for red), and a closing parenthesis. Press Enter, and the function will display the count of cells with the specified color in the range.

In conclusion, while Google Sheets doesn't have a built-in way to count cells based on their color, a combination of conditional formatting, data validation, and Google Apps Script can help you achieve this. Whether you're marking and counting cells based on their color for data analysis or just for fun, these methods can save you time and effort in your Google Sheets workflow. Happy counting!