Count and sum by color in Google Sheets

Function by Color allows you to calculate cells coloured in a certain way in any range in Google Sheets.

Before you start

Note. Go to File > Spreadsheet settings in the Google Sheets menu and see if you have a locale selected there. If not, please set one and confirm your action.

To our regret, Google Sheets takes some time calculating custom formulas. If you have a large table, please wait a few seconds before the value of the built formula changes from "0" to a correct one.

The Refresh results option also works a bit slow since it recalculates all custom formulas created by the tool.

How to count and sum values by fill and font color

Start Function by Color

Go to Add-ons > Function by Color > Start in the Google Sheets menu to access the utility:
Start Function by Color.

Tip. You will also find the add-on in Power Tools — a collection of all Ablebits add-ons for spreadsheets:

  1. Open Add-ons > Power Tools > Start in the Google Sheets menu:
    Run Power Tools.
  2. Then either click on the tool icon and pick the Function by color option:
    Find the add-on on the smart toolbar.
    Or access the add-on from the Process group:
    Function by Color in the Process group.

How to count and sum values by fill and font color

You will see the add-on pane with a few settings to adjust:
Fine-tune the options to calculate exactly what you need.

  1. Define the range of cells where you want to calculate colored cells.
    Tip. Select a range of cells before running the tool and it will be picked up for processing. But if you run the add-on with a single cell being active in the sheet, that cell will be taken as a place for the result.

    To change the range, just enter it manually or click the Select range icon. The latter will open a special window allowing you to pick the necessary cells:
    Pick the range to calculate within.

    Tip. Use the Auto select button for the tool to identify your table automatically.
  2. Decide on the background and font colors that you want to calculate:
    1. Click the Color picker button and you will get a pop-up window inviting you to select a pattern cell from your sheet:
      Select a pattern cell directly from the sheet.
      Just click the cell of interest in your table (you can confirm your choice by hitting the Auto select button) and then click OK.
    2. Once the pattern cell is chosen, the Font color and Background color icons in the add-on will feature the corresponding hues.

      The checkboxes next to these icons let you decide if you want to calculate cells that share Font color only, or Background color only, or both hues.

      Tip. You can change these text and fill colors or set them from the beginning by clicking the corresponding icons and picking the required shade from the palette:
      Set a background hue using the palette.
  3. Single out the function you want to use for calculations from the Use function drop-down list. You can choose between the following functions: SUM, COUNT (to count numeric values only), COUNTA (to count both numeric and textual values), COUNTBLANK, AVERAGE, AVERAGEA, MIN, MAX, PRODUCT, MODE, STDEV, VAR, MEDIAN.
    Tip. If your task is to count cells with a particular color, it is best to choose COUNTA as it is the only function that works with text values.
  4. Select or enter the destination cell for the Function by Color formula in the Paste results to field. You can select the top-left cell for the results and the add-on will automatically adjust the range based on the next option.
  5. Use the Calculate in list to do one of the following:
    • insert one formula for the entire range:
      Calculate the entire range.
    • calculate each column individually:
      Calculate in each column.
    • count colored cells in each row in the range respectively:
      Calculate in each row.

      Tip. This way, if you want to check how many green cells there are in each row, you won't have to copy the formula manually.
  6. Tick off the last checkbox to have the add-on fill results with your pattern colors (hues that are used for calculations).
  7. If you don't really use the last two options often (Calculate in and Fill results with your pattern colors), click the icon with the upward pointing arrow to hide them. You can make them visible again at any time by clicking the arrow once more.

Hit Insert function to calculate all cells in the desired range based on the selected colors.

Note. To our regret, Google Sheets takes some time calculating custom formulas. If you have a large table, please wait a few seconds before the value of the built formula changes from "0" to a correct one.

The Refresh results option also works a bit slow since it recalculates all custom formulas created by the tool.

How to update the results

Note. By default, changes of the background color are not considered as a reason to update formula results in Google Sheets. Unfortunately, we can't control or bypass that.

If there are any changes only to the formatting in the range, there are 3 ways to update calculations:

  • If you use standalone Function by Color, go to Add-ons > Function by Color > Refresh results:
    Refresh results from the single add-on menu.
  • In Power Tools the Refresh results option resides in two places:
    • In the Smart Toolbar drop-down list:
      Refresh results if the changes took place in your spreadsheet.
    • And in the Google Sheets menu — Add-ons > Power Tools > Refresh results for Function by color:
      Refresh results from Power Tools menu.
  • One more way to make the formulas recalculate themselves is to change one of the values in the calculated range, e.g. add or remove a character.

How to edit existing formulas

The add-on offers an opportunity to quickly edit existing formulas: change colors and a way to calculate, pick another function or even source range.

Just select a cell with a formula you want to adjust and click the corresponding option from the Function by Color menu:
Edit selected formula.

Tip. If you use Power Tools, you will find the option in the drop-down list on the Smart Toolbar:
Edit formula from Power Tools.

The add-on pane will open, featuring all settings that were used to build this formula. Tweak whatever seems necessary and hit Insert function to get the updated result in the same cell.

Responses

I am not able to do . I have 500 cells and I like to count 3 colors used . these are in 7 heads.

Reply

Hello, Hem,

Thank you for reporting a problem.

For us to be able to assist you better, please send us the screenshot of how your data is stored and of the result you're getting with our add-on.
Also, if it's possible, please share your spreadsheet with us (gapps.ablebits@gmail.com) with a description of your task. I kindly ask you to shorten the table to 10-20 rows.

We'll look into the problem and do our best to assist you.

Reply

it does not work for me

Reply

Hello, Dan,

I'm sorry to hear you've encountered difficulties with our tool.

Please email us to support@ablebits.com with the screenshots of your source data and the result you're getting after running the add-on.
We'll investigate the problem.

Thank you.

Reply

Hi,

I have found solution)

By some reasons, when you use POWER TOOLS in already formed table, SUM by color function doesn't "catch" cells color in "Source range" (even if cells have the same color and code e.g. #00ff00). After applying the function it give you "0".
You have two options:
1. Apply Google Sheet function "Paint format" from your "Pattern cell" to the cells in your "Source range".
2. Simulteniously select "Pattern cell" and correspondent cells in your "Source range" and apply to them the same color.
Don't forget "Refresh results" in POWER TOOLS after each actions!
After applying POWER TOOLS, all newcreated cells with correspondent color will be "catched".

Reply

Igor,

I think this is the issue I'm having in my google sheet. Where/how do I find "paint format" exactly?

Thanks

Reply

Hello, Alex,

I'm sorry you're having difficulties with the tool.

Would it be possible for you to share your spreadsheet with us (gapps.ablebits@gmail.com) with a description of your task?
We'd look into the issue and do our best to make our add-on work for you.
Thank you.

Tom Arild Raen says:
July 6, 2020 at 3:58 pm

Hi:)
Some of my cells are showing "0" even if its a copy paste of working cells with the exception of being a different column. At first i thought it was the copy paste that wrecked it, but it works for some columns thats the weird thing. Any idea why this is happening?

Reply

Hi,

Thank you for your message. Please try to click the Refresh results option. That should do the job. If not, please share a small sample spreadsheet with us (support@apps4gs.com). When sharing, make sure the option 'Notify people' is checked. To grant us access to your data, press the Share button at the upper right corner of Google Sheets and enter support@apps4gs.com.

We keep that Google account for file sharing only and do not monitor its Inbox. Please do not email there.

If you have confidential information in your records, please replace it with some irrelevant data, just keep the format. Thank you.

I haven't found the reason, but in some cases Sum function give an error (#ERROR!).
The reason of the error is two extra "f" in front of first color code.
Please compare:
Error: =SUM(valuesByColor("#ff00ff00"; "#000000"; '1'!A3:D10))
Correct: =SUM(valuesByColor("#00ff00"; "#000000"; '1'!A3:D10))
If you delete extra "f", everything work properly)

Reply

Thank you very much for your comments, Igor.

I'm afraid, there's currently an issue that has appeared recently due to some problems on the Google side. For some reason, Google Sheets occasionally stops reading custom formulas made by other add-ons. To our regret, our Sum by Color was also affected, but flipping the ranges for calculation one way and back with our Flip tool usually helps.

However, "ff00ff00" is an incorrect color code. If this code was returned to you by our add-on, please share an example spreadsheet with us (gapps.ablebits@gmail.com) with the colors you were trying to count.

We'll check what may be causing the problem.
Thank you.

Reply

I tried to use it by configure the most basic options, but it doesn't work. it seems bugged and the error is in russian???

Reply

Thank you for reporting this problem to us, Carlos.

For us to be able to assist you better, please send us the following details to support@ablebits.com:
- Reproduce the issue. If you get the same error message, please send us its screenshot.
- Describe in detail what steps you follow before the issue occurs. What options do you choose on each step of the add-on? The screenshots of the steps would be very helpful.

This information will help our developer understand what is causing this problem.

Reply

Is there a way to edit a function by color once it's already been made, or do I have to redo it? If it is possible, what are the steps to do this?
Thank you.

Reply

Thank you for your question, Megan.

You can edit this formula like any other formula in Google Sheets - select the cell with it and go to the formula bar to edit it. You can easily change the range and the required sheet name. The formula will recalculate itself accordingly.
As for colors, if you're not sure of their correct RGB codes, I'd recommend using the add-on to change them.

Reply

Thanks so much for the quick response. Is it possible to get the box back up that is initially used to create the function to change the RGB codes, or do I need to start over? Thanks again!

Thank you for the idea, Megan. πŸ™‚

I've just contacted our developers with this suggestion for a discussion. They will see if it's possible to introduce such a feature.
I can't give you any timing, but I can let you know if/when it is implemented.

In the meantime, to change colors correctly, please start the tool to build a new formula.

Hello Megan,

The recent upgrade of the Function by Color features a new option: Edit selected formula. it will help you adjust colors quickly. You can read more about it here.

Hi

See column J, my cells in green are not being summed (although I have selected the pattern colour)

Pls helP!

thanks

Reply

Hi Ray,

We replied to you by email, please check your Spam/Junk/Trash email folders if you don't see the message in your Inbox.

Reply

Hello team

kindly i'm looking to do the following:

1- i have a cell which has a red background
2- i Have an empty cell next to it
3- i need to have a number (any number) to get filled in the empty cell if the background color is red and zero if it's blank background

how can i do that πŸ™‚

Reply

Hello Rami,
Thank you for contacting us.

Unfortunately, we do not have an add-on that can help you with your task. Sorry for not being able to help you better.

Reply
YATIN KUMAR says:
August 6, 2019 at 8:22 am

How to do it for multiple colors?

Reply

Thank you for your question, Yatin.

We haven't provided for a way to process more than one colour at a time, so you need to enter one formula for each colour you want to count.
We will consider embedding this possibility in one of the future versions of the add-on.

Reply

Hello Yatin,

The recent upgrade of the Function by Color tool lets you process more than one color in one formula. You will still need to create separate formulas for each color, but you can then combine these formulas into a bigger one, like SUM, or COUNT(A), or AVERAGE, etc. and they will work.

Reply

thank you very much.

Reply

Don't know why, but I use the formula to counta cells in a green color (defined by conditional formatting) and referred to a cell that is not conditional formatted but using the same background color I want to count, and regardless of the cells colors in my row, the result is always "1" for counta and 0 for count. Why is that ?

Reply

Thank you for contacting us, Karina.

First, due to an issue on the side of Google, please make sure to sign out of all other Google accounts you may be logged in to.

Then, 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 option next to Function by color in Power Tools. The function should work correctly then.

Please let us know if you still have any difficulties.

Reply

This also gives me a value of 0 when searching for the green color.
See code: =COUNT(valuesByColor("#b7e1cd","#000000",'Dinner Guests'!F2:F49))

Why is this happening?

Reply
Katerina Bespalaya says:
November 1, 2019 at 5:43 pm

Hello,

We have just replied to your question by email. Please check your Inbox. Thank you.

Reply

Hi,
I try to use is to sum values in cells marked green, but it gives me #NAME? error saying that valuesByColor function is unknown. Any ideas how to fix it?

Than you!

Reply
Katerina Bespalaya says:
December 3, 2019 at 7:35 pm

Hi Karolina,

I've just sent you an email with the details we need to understand the problem better. Please provide us with the information requested in the email. Thank you.

Reply

I have the same problem, please let me know how to solve it

Hello Karolina,
Thank you for your comment. This problem may be caused by an issue with the way permissions are handled when you use more than one account in Google Sheets. Signing out of all other accounts and logging in just to the account with the subscription should fix this. If you share documents between the accounts, please make sure it is used under the necessary account.

Also, please keep in mind that 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 select the Refresh results under the Function by color in Power Tools to check if the function works correctly.

Hello!

I am having and issue with Power Tools. I need to get the total of each color in the range but I end up getting a '1' value.

Thanks!

Reply
Katerina Bespalaya says:
December 13, 2019 at 1:27 pm

Hello Mary,

Please note that our tool can't process more than one color at a time, so you need to enter one formula for each color you want to count.

Besides, 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. Additionally, our tool doesn't support the Theme colors which is a relatively new formatting tool in Google Sheets.

If the locale is set and the the standard Fill colors are used in your spreadsheet, then please contact support@ablebits.com for further assistance.

Reply

Hi,

I'm getting Unknown function: 'valuesByColor'. Does this function work when locale is set to United Kingdom? I'm actually trying to add cells that are not filled ie =SUM(valuesByColor("#ffffff", "#000000", 'Revolut Transactions'!G124:G129)).

Reply

Hi Mark,
Thank you for contacting us.

We have just replied to you via email. Please check your Spam/Junk/Trash email folders if you still don’t see our email in your Inbox. Thank you.

Reply

Hi,

I'm getting #NAME? Error Unknown function: 'valuesByColor'. I already set the locale (Thailand) but it's still not working.

Reply

Hi Pat,
Thank you for contacting us. This problem may be caused by an issue with the way permissions are handled when you use more than one account in Google Sheets. Signing out of all other accounts and logging in just to the account with the subscription should fix this. If you share documents between the accounts, please make sure it is used under the necessary account.

If not, please select the Refresh results under the Function by color in Power Tools. The function should work correctly then.

Reply

Hi,

I installed power tools, but when I try to use it on my spreadsheet it doesn't allow to click on it?
I selected the locale and restarted my computer. What am I missing?

Thank you

Reply

Hi Rick,

Thank you for your interest in our product.

It looks like add-ons from G Suite Marketplace are prohibited by your organization on the domain level. Please contact your administrator. He/she should be able to check this in the Google Admin console and whitelist the tool for you or all users if possible.

Reply

i just want to count the coloured cells, even if they are empty. This formula doesn't allow me to do so.

Reply

its sorted, i can use COUNTA()

Reply

Hello Anurag,

We are glad to hear that you have sorted out the problem.

If there are colored cells with some data and empty colored cells in the selected range and you want to count all of them, the COUNTA function is the best option in this case.

Hi there,

I see the same question I want to asked has already been asked in August 2019 (See below)
Could you tell me if this has been solved yet as I would really like to count more than one color.
I hope to hear from you soon!
Thanks,

Kat

YATIN KUMAR says:
August 6, 2019 at 8:22 am
How to do it for multiple colors?

Reply

Natalia Sharashova (Ablebits.com Team) says:
August 6, 2019 at 8:32 am
Thank you for your question, Yatin.

We haven't provided for a way to process more than one colour at a time, so you need to enter one formula for each colour you want to count.
We will consider embedding this possibility in one of the future versions of the add-on.

Reply

Hi Kat,

Thank you for contacting us. I'm really sorry but our development team is still working on this feature. We will let you know once it is available. Our apologies for any inconvenience.

Reply

Hi Kat,

The recent upgrade of the Function by Color tool lets you process more than one color in one formula. You will still need to create separate formulas for each color, but you can then combine these formulas into a bigger one, like SUM, or COUNT(A), or AVERAGE, etc. and they will work.

Reply

Hi,
I have been able to successfully use function by color to count how many cells are a certain color, but is it now possible to take it a step further and count only cells that have a certain string of text in them? For example if I have 20 green cells, 3 of them have the word "Sale" in them, while the other 17 have other words. Is it possible to use the countif function together with the backgroundcolor function to count how many cells have the word Sale in them? If so how can I nest the two functions correctly?

Reply

Ok scratch that, I've figured out how to do it. Now for the even next step, is there a way to create a list that shows me how often each word was mentioned in all the cells with a green background color?

Reply

Hi Mo,

Sorry, the add-on can't help with this task, however, you can have a look at this blog article and find a solution there:
https://www.ablebits.com/office-addins-blog/2017/06/29/countif-google-sheets/#countifs

Hi, would it be possible to extend the sum colours feature to allow a choice of using the colour of a cell, so the function then instead of hard-coding the colour uses whatever the colour is of that selected cell.
This would allow greater flexibility if you decide to replace a colour across the sheet.

Reply

Hi Daniel,

Thank you for your comment. First off, it is possible to update the formulas created by the add-on. You may either edit a formula in the add-on or manually enter the name of the color from the Google Sheets color palette and the change will be applied.

If this is not exactly what you need, please clarify. If you send us any screenshots illustrating your scenario to support@ablebits.com, it'll be very helpful. Thank you!

Reply

I start using the app today but it is one of the easy and must well develop for all to use.

Thanks so much

Very easy to understand.

The Gambia, West Africa.

Please try it

Hello Sunks,

Thank you so much for your feedback! We're happy to hear you enjoy using our software.

If it's not too much trouble for you, we would appreciate it if you rate our add-on and write a few words on Google Workspace Marketplace. Your positive feedback motivates us much better than sales numbers. πŸ™‚

Thank you in advance and have a great day!

Ask a question (posted publicly)

If you have any questions or issues with this add-in, please feel free to post your concerns in the comments area. As soon as we answer, a notification message will be sent to your e-mail. If you do not want to share your thoughts in public, please contact us at support@ablebits.com.