Skip to main content
 

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

Author: Sun Last Modified: 2024-08-30

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     

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


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:
vba code to select data range

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

select a cell with the font and background color you want to count

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.

a dialog pops out to display the count result


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 offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Enhanced with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

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 Kutools Plus> Count by Color. See screenshot:

click Count by Color feature of kutools

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:

set options in the dialog box

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:

click Generate report       count result will be displayed


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 Kutools Plus > 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:

set options in the dialog box

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:

sells with conditional background color will be counted

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 30 days, please download and have a free trial now.


Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


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!