跳到主要内容

如何在Excel中使用条件格式按颜色对单元格进行计数/求和?

在Excel中,您可以使用条件格式为某些单元格着色。 现在,本教程将告诉您一些便捷的方法,以便在Excel中使用条件格式快速按颜色对单元格进行计数或求和。

通过VBA按字体颜色和背景计数单元格

使用 Kutools for Excel 的条件格式按字体颜色对单元格进行计数/求和 好主意3      玩

使用 Kutools for Excel 的条件格式按背景颜色对单元格进行计数/求和 好主意3      玩


箭头蓝色右气泡 通过VBA按字体和背景色对单元格进行计数

在Excel中,只有VBA代码可以基于特定的字体和背景颜色快速计数单元格。

1。 按 Alt + F11键 打开钥匙 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块 并将以下VBA代码复制并粘贴到弹出窗口中 模块 窗口。

VBA:根据字体和背景颜色对单元格进行计数。

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。 点击 运行 按钮或按下 F5 键运行代码,然后在弹出对话框中选择所需的范围。 看截图:
doc-count-condition-color-1

4。 点击 OK,然后选择一个要基于其字体和背景颜色进行计数的单元格。 看截图:

doc-count-condition-color-2

5。 点击 OK。 然后会弹出一个对话框,告诉您有多少个单元格具有与该范围内所选单元格相同的背景色和字体颜色。

doc-count-condition-color-3


箭头蓝色右气泡 使用 Kutools for Excel 的条件格式按字体颜色对单元格进行计数/求和

在Excel中,不能仅使用条件格式按字体颜色对单元格进行计数或求和。 但是,有一个方便的加载项称为 Kutools for Excel 可以帮助您快速解决此问题 按颜色计数 功能。

Kutools for Excel, 与超过 300 方便的功能,使您的工作更加轻松。 

免费安装 Kutools for Excel,请执行以下操作:

1.选择要计数的范围或使用条件格式按字体颜色对单元格求和,然后单击 Kutools 加> 按颜色计数。 看截图:

doc-count-condition-color-4

2.然后在 按颜色计数 对话框中选择 条件格式上色方式 列出并 字体颜色类型 清单。 然后,您可以在对话框中查看计数和汇总的结果。 看截图:

doc-count-condition-color-5

备注:如果要将计算结果作为报告输出,可以单击 生成报告我在n 按颜色计数 对话框,然后将在新工作簿中构建报告。 看截图:

doc-count-condition-color-6      doc-count-condition-color-7


使用 Kutools for Excel 的条件格式按背景颜色对单元格进行计数/求和

如果要使用条件格式按背景色对单元格进行计数或求和,也可以应用 按颜色计数 实用程序 Kutools for Excel.

1.使用条件格式选择要计数的范围或按背景色求和的单元格,然后单击 Kutools 加 > 按颜色计数.

免费安装 Kutools for Excel,请执行以下操作:

2.然后在 按颜色计数 对话框中选择 条件格式上色方式 列出并 背景 颜色类型 清单。 然后,您可以在对话框中查看计数和汇总的结果。 看截图:

doc-count-condition-color-8

备注:如果要将计算结果作为报告输出,可以单击 生成报告 ,在 按颜色计数 对话框,然后将在新工作簿中构建报告。 看截图:

doc-count-condition-color-9

单击此处以获取更多关于按颜色计数的信息。

小费。 按颜色计数 实用程序中,您还可以仅使用标准格式或标准格式和条件格式按背景颜色或字体颜色对单元格进行计数/求和/平均。 如果您想在30天内无限制地应用按颜色计数, 请下载并立即免费试用。


箭头蓝色右气泡 通过字体颜色或背景颜色计算单元格


最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
Could you please teach me VBA codes I would like to learn VBA using excel sheet
This comment was minimized by the moderator on the site
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à . Mình cám ơn.
This comment was minimized by the moderator on the site
Hi,
How do I modified the code for the cell contain conditional formatting? Because it count the background as "blank".


Thanks.
This comment was minimized by the moderator on the site
Sorry I have no idea about the VBA code.
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
hi


kindly send the above VBA code same code is I need please help.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations