How to count cells by color in Google Sheets

Natalia Sharashova by , updated on

If you color-code your data in Google Sheets, you've probably noticed the lack of standard formulas that summarize this kind of information. This is why we added a custom function that considers the font and background color of the cells when applying all basic operations.

You can find it among the smart features of our Power Tools add-on or as an individual tool: Function by Color. Both offer a 30-day trial period and two subscription plans: 12-month and lifetime.

Tip. Watch this short demo video or look through the detailed description with the screenshots below.

How to count colored cells

Let's take one of the most common tasks with colored cells in a spreadsheet: counting cells that have the same formatting. Say, here I have a list of grades and I want to see how many times each test was passed, i.e. count all green cells in a column:
Count colored cells with different types of values.

If you work with similar ranges that comprise different types of records: numbers, text, or date values, embrace the COUNTA function with the Function by color tool.

For a start, open the tool to sum by color. In Power Tools, you will see it right on the smart toolbar:
Open Function by color tool in Google Sheets.

Here are six simple settings you need to specify to get the results:

  1. The range with the color-coded data that you want to check: I pick the columns with the test results.
  2. The pattern cell. The function will take its font and/or background color and look for the same in other cells. I pick the fill color of B2 as an example.
  3. The function. When you want to count cells with particular formatting, it's best to choose the COUNTA function because it is the only one that works with non-numeric values. This way we can be sure that the format of the data in the cells will not impede with the results.
  4. The place for results. I want to count in each column so it is three cells for me.
  5. How to apply it. We can choose to count cells in each row, column, or in all selected cells. As I want to count green cells for each test, I choose to Calculate in each column. If I wanted a general result for all three tests, I'd choose the "entire range".
  6. The formatting of cells with the result. You can have them filled with the same colors as you count by selecting just one checkbox.

Use Sum by color to count green cells.

Once I click Insert function, the tool adds the formula under each column, so I will see the results for each test:
The function shows how many green cells are in each column.

Let me break down its syntax and explain each part:

  • =COUNTA is one of standard Google Sheets functions you pick to use with the colored cells.
  • ligh green 3 is the cell color considered for the calculations, i.e. the background color of the pattern cell.
  • "" is empty since I don't consider the font color of the pattern cell.
  • B2:B18 is the range to check for colored cells. It looks at cells in column B in my example.

How to sum values by color

Say, I'm keeping track of classroom equipment orders. I denote the ordered things by yellow background color, items on the way by blue, and delivered equipment by green:
Sum same-colored cells.

My task is to see how many desks, computers, and other supplies are on the way at the moment. Color is the only difference these numbers have in my table. So I open the tool to sum by color and use the following settings:

  1. I select the entire range with my data to check it.
  2. I pick C2 as a pattern cell to specify the format of items I want to calculate.
  3. Select the SUM function to add up the numbers from the green cells.
  4. Pick cells to place the resulting calculations for each item.
  5. To see the number of shipped items for every product, apply the function to each row.

Sum values by color.

Click Insert function to get the formula after each line in your table.
See the results inserted for each line.

The convenience of getting the formula is that you can modify any of its parts and paste it wherever you need in your Google spreadsheets.

Update the results

Do you remember that Google Sheets don't have functions that work with color? This means they don't count changes to cell formatting as a reason to re-calculate your formula results. The good news is that both workarounds you can use are very simple.

  1. You can change any value within the calculated range. Say, you are counting green cells in A1:C254. You can simply add a character to any of the cells in this range, and then remove it to get the updated results.
  2. If you have a lot of valuesByColor formulas in your sheet, click on the Refresh option that is right under the Function by color in Power Tools to update all formulas in one go.
    Refresh Sum by color results.

Edit formulas

Another way to change the result is to edit the entire formula. But if there's only a couple of settings you'd like to choose, you don't have to build the entire formula anew. It is enough to click a cell that already contains a formula and pick the option to edit it:
Edit selected valuesByColor formula.

The add-on will open with all the setting that were used to create the selected formula. You can adjust some or all of them – ranges, colors, pattern cell, function – and insert everything back.

Troubleshooting

If you see an error in place of the formula, you may happen to be working with a file that has no locale. When this happens, our function doesn't know what delimiters it should use, so it ends up giving you an error. If you see this, please go to File > Spreadsheet settings... in Google Sheets and make sure you have the locale set.

Table of contents