Note: The other languages of the website are Google-translated. Back to English

How to count or sum cells based on the font colors in Excel?

How could you get the number of cells or sum all the cells which contain a particular font color in Excel? For example, I have a range of data in a worksheet as following screenshot shown, and now I want to respectively count or sum the cells that have a red, blue and black font color. Normally, there is no direct way to deal with this task, here, I will talk about some tricks for soling this job.

Count or sum cells based on font colors with User Defined Function

Count or sum cells based on font color with some useful functions

Count or sum cells based on font color with an amazing feature-Count by Color


Count or sum cells based on font colors with User Defined Function

Count cells based on font colors:

To calculate the number of cells with specific font colors, please do as these:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Count cells based on font colors:

Public Function CountColour(pRange1 As Range, pRange2 As Range) As Double
'Update by Extendoffice
Application.Volatile
Dim rng As Range
For Each rng In pRange1
    If rng.Font.Color = pRange2.Font.Color Then
        CountColour = CountColour + 1
    End If
Next
End Function

3. Then save this code and go back to the worksheet, and then enter this formula in to a blank cell =CountColour(A1:D10,A2) , see screenshot:

Note: In the above formula, A1:D10 is the range that you want to use and A2 is the cell with a particular font color that you want to count.

4. After typing the formula, press Enter key, and you will get the number of cells with red font colors. If you want to count other font colored cells, please repeatedly enter the formula as possible as you need. You will get the following results:


Sum cells based on font colors:

To sum cells based on font colors, the following User Defined Function can help you.

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Sum cells based on font colors:

Public Function SumByColor(pRange1 As Range, pRange2 As Range) As Double
'Update by Extendoffice
Application.Volatile
Dim rng As Range
Dim xTotal As Double
xTotal = 0
For Each rng In pRange1
    If rng.Font.Color = pRange2.Font.Color Then
        xTotal = xTotal + rng.Value
    End If
Next
SumByColor = xTotal
End Function

3. Then save this code and return to the original worksheet, and then enter this formula =SumByColor(A1:D8,A1) into a blank cell, see screenshot:

Note: In the above formula, A1:D10 is the range that you want to use and A2 is the cell with a particular font color that you want to sum.

4. Then press Enter key, and you will add up all cells with red font colors. If you want to sum other font colored cells, please repeatedly enter the formula. You will get the following result:


Count or sum cells based on font color with some useful functions

May be the User Defined Function is troublesome for you to save and apply, here, I will recommend you a handy tool-Kutools for Excel, with its advanced functions, you can solve this task quickly and easily.

Tips:To apply this COUNTBYFONTCOLOR and SUMBYFONTCOLOR features, firstly, you should download the Kutools for Excel, and then apply the feature quickly and easily.

After installing Kutools for Excel, please do as this:

Count cells based on font colors:

1. Click a cell where you want to put the count result, and then click Kutools > Kutools Functions > Statistical & Math > COUNTBYFONTCOLOR,see screenshot:

2. In the Function Arguments dialog box, specify the data range and color index cell that you want to count by font color, see screenshot:

3. And then, click OK button, you will get the first count result, to get other results, you just need to copy this formula and change the cell references to your need. See screenshot:


Sum cells based on font colors:

1. Click a cell where you want to put the count result, and then click Kutools > Kutools Functions > Statistical & Math > SUMBYFONTCOLOR,see screenshot:

2. In the Function Arguments dialog box, specify the data range and color index cell that you want to sum by font color, see screenshot:

3. And then, click OK button, you will get the first sum result, to get other results, you just need to copy this formula and change the cell references to your need. See screenshot:

Click to Download Kutools for Excel and free trial Now!


Count or sum cells based on font color with an amazing feature-Count by Color

Kutools for Excel also provides an easy feature- Count by Color, with this utility, you can quickly get the calculation result such as count, sum, average cells and so on by the background color, font color, conditional formatting as you need.

Tips:To apply this Count by Color feature, firstly, you should download the Kutools for Excel, and then apply the feature quickly and easily.

After installing Kutools for Excel, please do as this:

1. Select the data range that you want to count and sum based on different colors.

2. Click Kutools Plus> Count by Color, see screenshot:

3. In the Count by Color dialog box, choose Standard formatting from the Color method drop down, and select Font under the Count type drop down, and the cells with same font colors have been counted, added up, averaged and so on, see screenshot:

4. And then click Generate report button, you will get the statistics in a new workbook. See screenshot:

Click to Download Kutools for Excel and free trial Now!


More articles:

  • Count And Sum Cells Based On Background Color In Excel
  • Supposing you have a range of cells with different background colors, such as red, green, blue and so on, but now you need to count how many cells in that range have a certain background color and sum the colored cells with the same certain color. In Excel, there is no direct formula to calculate Sum and Count of color cells, here I will introduce you some ways to solve this problem.
  • Sum / Count Bold Numbers In A Range Of Cells In Excel
  • When you have a data range which contains some bold numbers in a worksheet, and now you want to sum or count only the bold cells, of course you can add them up one by one manually, but it will be time-consuming. How could you sum or count only the bold cells in Excel with an easy and quick way?
  • Apply Color Gradient Across Multiple Cells
  • In Excel, we can easily fill background color to a cell or multiple cells, but, sometimes, we need the color be filled gradient as following screenshot shown, how could get the color gradient in a cell or across multiple cells in Excel?
  • Concatenate Cell Columns And Keep Text Color In Excel
  • As we all known, while concatenating or combining cell columns into one column, the cell formatting (such as text font color, number formatting, etc) will be lost. This article, I will introduce some tricks to combine the cell columns into one and keep the text color as easily as possible in Excel.

Count or sum cells based on font / background / conditional formatting color:

Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!

The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Comments (52)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thank you so much! It works like wonder!
This comment was minimized by the moderator on the site
Hi, when i use this formula it keeps coming up with "Compile Error: Must be first statement on the line" and it has highlighted the "Function" on the first line of the formula. Help??
This comment was minimized by the moderator on the site
May be you did not insert a module instead copied the code on the screen after Alt+F11
This comment was minimized by the moderator on the site
How do we do well to access?
This comment was minimized by the moderator on the site
it works very good and so nice function. thank you.
This comment was minimized by the moderator on the site
super cool, helped me a ton. if you don't mind me asking. when i try this on a colored cell number affected with "Conditional Formatting" it seems to see all the numbers as a single color. are there any way to have the program recognize that the color is different.
This comment was minimized by the moderator on the site
I use a very similar method but have been playing with MULTI Colored fonts... say [Only the BOLD word is red], fingers crossed you have a thought as to how I may achieve this! Cheers Eddie
This comment was minimized by the moderator on the site
Hello, I keep getting an error as follows "Ambiguous name detected: SumByColor". What am i doing wrong?
This comment was minimized by the moderator on the site
I got this message when I tried to apply the same thing to another spreadsheet. When you go to insert module and copy in the text change it to SumByColour (different spelling and note there are two instances of it in the text). Then when I tried to use the formula in my second spreadsheet the new spelling came up which I selected and now the function works in this spreadsheet too. I hope this works for you because I am finding it extremely useful for various spreadsheets I work with.
This comment was minimized by the moderator on the site
Excellent work! Saved my wife's night! Thx
This comment was minimized by the moderator on the site
IT worked ,, thank you But when I save and close worksheet then re-open, it shows (#Name?) I've saved it (Macro-enabled)
This comment was minimized by the moderator on the site
Click to enable macros on the yellow bar at the top of the page when you open your document and your formulas will come back. Hope this helps.
This comment was minimized by the moderator on the site
MYTawalbeh, I had the same issue. You have to save the workbook as a macro enabled workbook so the macro copies over. Otherwise you will continue to have the error because the macro isn't being copied over.
This comment was minimized by the moderator on the site
the countcolor function includes the spaces between the cell that has that specific color. can you fix this? thanks alot!
This comment was minimized by the moderator on the site
thank you very much... needed a little debugging but I think that's because nothing is ever cookie cutter, what I did to fix my issues may be different than what anyone else may need to do (based on version, etc.) but once I took out the rem'd line and made sure that I was pointing to the right fields and format field to do the comparison to, it worked like a charm.
This comment was minimized by the moderator on the site
I followed your directions for the count but in the cells that I have =CountColour(...) I have the #NAME error. I have multiple tabs, so I put the code in the sheet where I want to use it but I still got the error, so then I put it in a module. What am I missing??
This comment was minimized by the moderator on the site
Click the Microsoft Office Button , and then click Excel Options. Click Trust Center, click Trust Center Settings, and then click Macro Settings. Click the options to enable macro
This comment was minimized by the moderator on the site
Hi I need to count the number of cells in orange font from cell range B:B if Cell Range AB says 'Ventura' The above allows you to count according to one criteria but doesn't allow a second - I have tried but I have never written macros before and cannot get this working. Urgent help needed please? Thank you Leanne
This comment was minimized by the moderator on the site
Sir#name error aa rahi hai
This comment was minimized by the moderator on the site
How do I get the spread sheet to automatically update? If my data/color changes the sum doesn't update until I select the cell with the formula, hit F2, and then click off the cell. I want my sheet to automatically update as the data changes. Thanks.
This comment was minimized by the moderator on the site
Hi! Works great, thanks. However, doesnt work for cells with more than one colour. Is it possible to update this code to do this? Nikki
This comment was minimized by the moderator on the site
Is there any way to count the cells by colour without Kutools?
This comment was minimized by the moderator on the site
Great read and works awesome but could someone please tell me how to apply this to multiple sheets. If anyone can, this will be brilliant for what I need and will be much appreciated indeed.
This comment was minimized by the moderator on the site
Great read and working brilliant however is it possible for anyone to explain how I could apply this to a multiple set of sheets?? Any idea will be much appreciated so cheers in advance.
There are no comments posted here yet
Load More
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations