How to count colored cells in Google Sheets

When you use different colors to organize your data in Google Sheets, you might find there are no built-in formulas to easily summarize data based on color. To address this, we introduced several custom functions that take into account both the font and background color of cells for basic operations, making it possible for your Google Sheets to sum by color or count cells by color.

You will find these functions among the smart 40+ features of our Power Tools collection or as an individual tool: Function by Color. Both offer a 30-day trial period and two subscription plans: 12-month and lifetime.

How to count colored cells in Google Sheets

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're dealing with ranges that include various data types like numbers, text, or dates, consider using the COUNTA function from 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, B2:D18.
  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. To count cells with a particular number format, it's best to choose the COUNTA function because it is the only one that works with non-numeric values. This way you can be sure that the data format in the cells will not impede the results.
  4. The place for results. I want my Google Sheets count cells by color in each column so it is three cells for me, B19:D19.
  5. How to apply it. You 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:

  • =LAMBDA(vbc, IF(ISERROR(vbc), vbc is the service part that enables the formula to return exactly what Google Sheets replies with, whether it's "loading", some error, or the calculation result.

    Tip. You'll see this part only for COUNT, COUNTA, and COUNTBLANKS functions because of their peculiarities.

  • COUNTA(vbc) is one of standard Google Sheets functions you pick to use with the colored cells. vbc stands for valuesByColor.
  • valuesByColor is our custom function that handles colors.
  • light 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.
  • D2:D18 is the range to check for colored cells. In my example, it looks at cells in column B, C & D respectively.

How to sum colored cells in Google Sheets

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, B2:F8
  2. I pick C2 as a pattern cell to specify the format of items I want to calculate.
  3. Select the SUM function to tally numbers from blue cells.
  4. Pick cells to place the resulting calculations for each item, G2:G8
  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.

Google Sheets: sum by all colors in the table

The updated Function by Color lets you calculate not just one color per formula but all colors simultaneously.

Using the same data as above, I can find the total of all delivered supplies (green), tally those on their way (blue) or those ready for ordering (yellow).

I just need to switch to the All colors tab in the add-on and adjust the same settings:

  • The range is the same table, B2:F8.
  • I will sum data by all fill colors.
  • I also choose to calculate the entire range and have 1 formula inserted in A10.
    • Note. The formula returns the result in 2 columns: color & the total. So make sure there's enough space to insert the function. The result will show once there's room for it, but until then you may see the #REF! error if other data is on the way. Sum by all colors in Google Sheets.

Update the results

So, Google Sheets doesn't have native functions that work with color. This means your spreadsheet doesn't treat changes to cell formatting as a reason to re-calculate your formula results. The good news is that both workarounds in-store are elementary :)

  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 results option (right under the Function by color in Power Tools or under the Extensions menu for the single add-on) 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 are 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 settings necessary to create this selected custom 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 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 > Settings in Google Sheets and make sure you have the locale set.

Video: How to count colored cells in Google Sheets


Table of contents

164 comments

  1. Thanks for sharing this power tool. its very useful for me.
    I'm using this tool to sum the amount for numbers in font red, once i change the word to black, the output figure doesn't change on its own, i will have to open the tool to click on refresh result.
    is there any shortcuts or auto refresh every time there's changes in the cell?

    • Hello lin,

      I covered this problem and solutions in this part of the article: Update the results

      If it's not too much trouble for you, we would appreciate it if you rate Function by Color and maybe write a few words on Google Workspace Marketplace. Your positive feedback motivates us to provide the best experience for you and helps others understand how our product makes their life easier :)

  2. What if I'm using conditional formatting to color the backgrounds? Will these solutions work?

    • Hello John,

      Yes, the tool will read cell colors no matter whether you color them manually or using conditional formulas. Pay attention to this part: Update the results. You may need to refresh the results manually if only color changes take place.

  3. Is there a way to combine this with an IF function or something. I have a time off request form for my employees to fill out online and I pull the data from that into sheets. I want to highlight approved time off and have it automatically calculate by employee. I can color code by employee and get the right numbers since right now we're small, but I really don't want to use that many colors. I shared a sample with you. Let me know if this is something that can be done.

  4. Doesn't work. I have tried every solution posed by reponses to other questions. The Locale is set to the United States. I have refreshed the add-on, the webpage, and the browser. I have tried every combination of COUNT function, hex code vs color names, column, row, and entire range. I get a 1 calculated every time.

    Not worth the time.

    • Hello MaKayla,

      I'm sorry to hear you're having difficulties with the add-on.

      Sometimes it's wrong colors, sometimes the wrong formula or even your data format that cause the issue (e.g. when you enter a dollar sign right into a cell and believe it's a currency but it's actually text for Google Sheets). If you'd like, you can share your spreadsheet with us: support@apps4gs.com. I'll look into it and suggest what may be causing the problem.

  5. hi, I already share my google sheets with you. Can you please take a look with the formula that i want to use which is count cells by color in Google Sheets.

    thank you

    • Hi Ezzanur,

      I've corrected the formula in your spreadsheet. It was syntax that caused problems. Please use our Function by Color add-on to build formulas in the future to avoid such problems.

  6. How to count conditional formatting based on color by name and name is given by another column in google sheets

    • Hello Arun,

      For me to be able to help you, please share a small sample spreadsheet with us (support@apps4gs.com) with 2 sheets: (1) a copy of your source data (2) the result you expect to get. The result sheet is of great importance and often gives us a better understanding than any text description.
      I kindly ask you to shorten the tables to 10-20 rows.

      Note. We keep that Google account for file sharing only and don't monitor its Inbox. Please do not email there. Once you share the file, just confirm by replying to this comment.

      I'll look into your task.

  7. I Have an issue when is select the cell with colour always results showing 1.
    but in my file multiple columns have single colour but still showing 1.

    Please help

    • Hello Neha,

      First, please go to File > Spreadsheet settings and see if you have a locale selected there. If not, please set one and confirm your action, then select the Refresh results in the tool, the function should work correctly then.
      Also, if you're not the owner of the spreadsheet, ask the owner to start the add-on on their side and click Refresh results for you.

      If these don't help, please share your spreadsheet with us: support@apps4gs.com, and specify where the problem formulas are. I'll look into the issue.
      To grant us access to your data, press the Share button at the upper right corner of Google Sheets and enter support@apps4gs.com.
      Note. We keep that Google account for file sharing only and don't monitor its Inbox. Please do not email there. Once you share the file, just confirm by replying to this comment.

  8. It does not work for me (even I changed the locale...)

  9. My results always come back with 1.
    Even though I can hand count and see 18...

    My formula:
    =COUNTA(valuesByColor("#4285f4", "", A:A))
    Or I add "black", still same result.

    I've tried with multiple colours and always returns the same result as 1...

    Is it just me?

    • FYI, also tried with non-coded colors,
      ie. "light red 3" etc

      • Hello Rhys,

        A lack of locale in the spreadsheet may prevent the function from calculating the results as it doesn't know what delimiter should be used. Please go to File > Spreadsheet settings and see if you have a locale selected there. If not, please set one and confirm your action, then Refresh results.

        If this doesn't help, please share an editable copy of your spreadsheet with us: support@apps4gs.com, I'll look into the problem. If you have confidential information there, you can replace it with some irrelevant data, just keep the format.

        Note. We keep that Google account for file sharing only, please do not email there. Once you share the file, just confirm by replying to this comment.

  10. What if I wanted to count how many times, for example, the text "apple" occurred with the yellow cell colour? "apple" occurred in the purple colour? "orange" occurred with the yellow cell colour? Etc

  11. I am experiencing the same thing. The results are always zero. May I please ask for a sample spreadsheet? Thank you in advance.

    • Hello Adrian,

      I'm sorry, I'm afraid we don't have the spreadsheet with examples for this blog post saved.

      For us to be able to help you, please consider sharing a small sample spreadsheet with us (support@apps4gs.com) with your data AND the formula that returns zeros. I kindly ask you to shorten the table to 10-20 rows.
      Note. We keep that Google account for file sharing only and don't monitor its Inbox. Please do not email there. Once you share the file, just confirm by replying here.

  12. Is it possible to count all cells within a range that are NOT of a specific color?

    • Hello Bogdan,

      Sure:

      1. Count all cells in the range using COUNTA.
      2. Count the number of cells of that specific color that you don't want to count.
      3. Subtract the latter from the former.
  13. THANK YOU!
    This helped a lot :)

  14. Hey, i want to count green cells but it's not working.
    Can you help me ?
    Thanks

    • Hey Denis,

      Thank you for sharing your file. I've just opened it and the result of the formula states 4, which is correct. By default, COUNTA counts all coloured cells in a dataset, including text values and empty cells.
      Please let me know the result that you expected, and I'll help you pick the correct function.

  15. This hack saved me! Another website was making use a script but it was useless. This was easy! Thank you!

  16. I have STRAWBERRIES on RED colour and APPLES on RED COULOUR. (strawberries on green and also apples on green)
    I used this "=COUNTA(valuesByColor("#ff0000", "#000000",'2-6 SEP'!5:17))" but I get the total of both fruits. I need to know how many apples on red colour I have.

    Where should I add and what, in my formula, in order to get the correct answer.
    Thank you in advance!

  17. Hi, I was wondering what function to use to count color in a range with, say, the letters "AB" in the cell also. So count red cells that have "KO" in them.

    • Hi Ben,

      To count cells based on several conditions, you would normally use COUNTIFS. However, since our valuesByColor returns the list of values ​​from cells, it cannot be wrapped in COUNTIFS.
      We've been asked to introduce this functionality and are going to check if it's technically possible to implement something like this in the future. But for now, I'm afraid there's no simple workaround. I can only offer to try and use Scripts. Here's an overview of Google Apps Script with a lot of helpful content and links:
      https://developers.google.com/apps-script/overview

      I wish I could help you better.

  18. Is it possible to quickly edit the formula once it has been set? For example, if the pattern cell needs to be changed, is there a quick way to accomplish this? Also, if the range shifts in sheets, will the tool auto adjust?

    • Thank you for your questions, Colin.

      Once the formula is set, you can edit its arguments in the formula bar.
      If the pattern cell changes, the quickest way to check its new hex colors is to select the cell, click Fill/Text color > Custom. You'll see what color is used in the pattern cell right away. You can copy and paste it to the formula replacing the existing color.

      Yes, currently, if the range shifts (within the same sheet), the formula auto adjusts.

  19. I would like to count cells which are marked green. The goal is to know how often people have been available for something which we code with green and red background of the cell.
    Is there a possibility to count the green background cells if there is no number/text in the cell?
    Thanks for your support.

    • At the moment, Function by color counts all cells with the same background, whether blank or with data.
      To count only empty cells, create a formula with our tool and then manually substitute COUNTA with COUNTBLANK in it.

  20. When I sort this column, it is changing the data of the row. The forumal in row 2 will say it is counting row5. How do I get the rows to lock while sorting?

  21. I'm trying to use the sort by color COUNTA function in order to quickly tally my schedule items (which I have sorted by colour). In my schedule, I have time increments of 15 minutes, but many things obviously take longer than that; in these cases, I merge the cell to take however much time it needs. In my tally sums, I generally just count up the number of 15 minute periods something takes and then multiply it by 15 for the total number of minutes. Unfortunately, though, I can't seem to find a way to make the sort by color function recognize these merged cells as covering more space than a single cell. Is there a good way to do this?

  22. Hi, excuse me I just want to filter by color, is this possible?

  23. First formula I try using the wizard, I got this:
    =====
    Error
    TypeError: Не удается обнаружить функцию indexOf в объекте TypeError: Не удается прочитать свойство "sBackgroundPatternArg" объекта null.. (line 3082).
    =====

    I tried aligning the функцию below the объекта threshold, but it didn't свойство...

    Большой!

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)