Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to count/sum cells by colors with conditional formatting in Excel?

In Excel, you may color some cells by using conditional formatting. Now this tutorial will tell you some handy and easy methods to quickly count or sum the cells by color with conditional formatting in Excel.

Count cells by font color and background by VBA

Count/sum cells by font color with conditional formatting by Kutools for Excel good idea3      play

Count/sum cells by background color with conditional formatting by Kutools for Excel good idea3      play


Quickly Count/Sum cells by background or fomt color in Excel

In some cases, you may have a range of cells with multiple colors, and what you want is to count/sum values based on same color, how can you quickly calculate?
With Kutools for Excel's Count by Color, you can quickly do many calculations by color, and also can generate a report of the calculated result.  Click for free full featured trial in 60 days!
doc count by color 1
 
Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 60 days.

arrow blue right bubble   Count cells by font and background color by VBA


In Excel, only VBA code can quickly count cells based a specific font and background color.

1. Press Alt + F11 keys to open Microsoft Visual Basic for Applications window.

2. Click Insert > Module and copy and paste below VBA code to the popping Module window.

VBA: Count cells based on a font and background color.

Sub DisplayFormatCount()
	'Updateby20150305
	Dim Rng As Range
	Dim CountRange As Range
	Dim ColorRange As Range
	Dim xBackColor As Long
	Dim xFontColor As Long
	On Error Resume Next
	xTitleId       = "KutoolsforExcel"
	Set CountRange = Application.Selection
	Set CountRange = Application.InputBox("Count Range :", xTitleId, CountRange.Address, Type: = 8)
	Set ColorRange = Application.InputBox("Color Range(single cell):", xTitleId, Type: = 8)
	Set ColorRange = ColorRange.Range("A1")
	xReturn        = 0
	For Each Rng In CountRange
		qqq           = Rng.Value
		xxx           = Rng.DisplayFormat.Interior.Color
		If Rng.DisplayFormat.Interior.Color = ColorRange.DisplayFormat.Interior.Color Then
			xBackColor   = xBackColor + 1
		End If
		If Rng.DisplayFormat.Font.Color = ColorRange.DisplayFormat.Font.Color Then
			xFontColor = xFontColor + 1
		End If
	Next
	MsgBox "BackColor is " & xBackColor & Chr(10) & "FontColor is " & xFontColor
End Sub

3. Click Run button or press F5 key to run the code, then select the range you need in the popping dialog. See screenshot:
doc-count-by-conditional-color-1

4. Click OK, then select a cell whose font and background color you want to count the cells based on. See screenshot:

doc-count-by-conditional-color-2

5. Click OK. Then a dialog pops out to tell you how many cells have the same background color and font color with the selected cell in the range.

doc-count-by-conditional-color-3


arrow blue right bubble   Count/sum cells by font color with conditional formatting by Kutools for Excel

In Excel, you cannot count or sum the cells by font color with conditional formatting only. However, there is a handy add-in called Kutools for Excel that can help you quickly solve this problem with its Count by Color feature.

  Kutools for Excel, with more than 300 handy functions, makes your jobs more easier. 

After free installing Kutools for Excel, please do as below:

1. Select a range you want to count or sum the cells by font color with conditional formatting, then click Enterprise > Count by Color. See screenshot:

doc-count-by-conditional-color-4

2. Then in the Count by Color dialog, select Conditional Formatting under Color method list and Font under Color Type list. Then you can view the result of counting and summing up in the dialog. See screenshot:

doc-count-by-conditional-color-5

Note: If you want to output the calculating result as a report, you can click Generate report in the Count by Color dialog, then a report will be built in a new workbook. See screenshot:

doc-count-by-conditional-color-6      doc-count-by-conditional-color-7

pay attention1Kutools for Excel: The 300 functions you must have in Excel, you can free download from here

  Count/sum cells by background color with conditional formatting by Kutools for Excel

If you want to count or sum cells by background color with conditional formatting, you also can apply Count by Color utility of Kutools for Excel.

1. Select a range you want to count or sum cells by background color with conditional formatting, then click Enterprise > Count by Color.

After free installing Kutools for Excel, please do as below:

2. Then in the Count by Color dialog, select Conditional Formatting under Color method list and Background under Color Type list. Then you can view the result of counting and summing up in the dialog. See screenshot:

doc-count-by-conditional-color-8

Note: If you want to output the calculating result as a report, you can click Generate report in the Count by Color dialog, then a report will be built in a new workbook. See screenshot:

doc-count-by-conditional-color-9

Click here for more on Count by Color.

Tip.With Count by Color utility, you also can count/sum/average the cells by background color or font color with standard formatting only or both of standard and conditional formatting. If you want to apply Count by Color without limitation in 60 days, please download and have a free trial now.


arrow blue right bubble Calculate cells by font color or background color



Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Heather Heathfield · 3 months ago
    Hi,

    This is a great piece of VBA and works perfectly. Are you able to modify this code to make it a function and then be used as a formula?

    e.g.
    =DisplayFormatCount(A14:E14,A2,False) for counting background colour (Count Range, Colour Match Cell, type)

    =DisplayFormatCount(C29:D29,A2,True) for counting font colour

    I would like to you something like this for an input form of many tables and validation fields that are compulsory. I would then be able to count how many fields that have not been completed correctly.


    Cheers
  • To post as a guest, your comment is unpublished.
    Rajendhar · 6 months ago
    Could you please teach me VBA codes I would like to learn VBA using excel sheet
  • To post as a guest, your comment is unpublished.
    Long Tran · 8 months ago
    Chào bạn.

    VBA đếm ô màu rất hay, tuy nhiên bạn có thể sửa giúp mình để kết quả không hiện thành msg box mà hiện luôn trên ô excel chỉ định được không? thêm cả hàm sum, average nữa thì càng tốt :D . Mail của mình là tranvanlong.dne@gmail.com. Mình cám ơn.
  • To post as a guest, your comment is unpublished.
    falina · 1 years ago
    Hi,
    How do I modified the code for the cell contain conditional formatting? Because it count the background as "blank".


    Thanks.
    • To post as a guest, your comment is unpublished.
      Sunny · 1 years ago
      Sorry I have no idea about the VBA code.
  • To post as a guest, your comment is unpublished.
    Morton Wakeland · 3 years ago
    May I congratulate you on a most easily understood and well written VBA program to perform such a simple task - i.e., count the number of cells with a specific color derived from Conditional Formatting.
    It beats the pants of the monster program by Pearson, and his does not even work, at least in Excel 2013. Nor do other supposed counting programs work that I have tried. Yours is the only one!! This worked perfectly.
    Thank you, thank you, thank you.
    Best Holiday Wishes,
    Mort in Dallas
    • To post as a guest, your comment is unpublished.
      Naresh · 1 years ago
      hi


      kindly send the above VBA code same code is I need please help.