跳到主要内容

如何在Excel中的一系列单元格中求和/计数粗体数字?

如果您的数据范围包含工作表中的一些粗体数字,而现在您只想对粗体单元格进行求和或计数,那么您当然可以手动将它们一一加起来,但这会很费时。 您如何以一种简便快捷的方式对Excel中的粗体单元格求和或计数?

使用用户定义的函数(VBA和公式)计算范围内的粗体数字
使用用户定义的函数(VBA和公式)将范围内的粗体数字求和
使用 Kutools for Excel 多次单击以对某个范围内的粗体单元格进行计数和求和


使用用户定义函数计算范围内的粗体数字

下列 用户定义功能 可以帮助您快速获取粗体单元格的数量。 请这样做:

1。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic for Applications窗口.

2。 点击 插页 > 模块,然后将以下代码粘贴到 模块窗口.

VBA代码:在一系列单元格中计算粗体数字

Function CountBold(WorkRng As Range)
'Update 20220516
Dim Rng As Range
Dim xCount As Double
For Each Rng In WorkRng
    If Rng.Font.Bold Then
        xCount = xCount + 1
    End If
Next
CountBold = xCount
End Function

3. 然后保存此代码,然后键入此公式 = CountBold(A1:C9) 放入空白单元格,请参见屏幕截图:

文档计数粗体单元格1

4。 然后按 输入 键,您将计算A1:C9范围内的粗体单元格。

文档计数粗体单元格2

请注意:A1:C9 公式中的表示要使用该功能计算粗体单元格的范围,您可以根据需要进行更改。


使用用户定义的函数求和范围内的粗体数字

而且,如果您只想对数据范围内的粗体数字求和,我也可以创建一个用户定义的函数来解决它。

1. 按住 ALT + F11 键,然后打开 Microsoft Visual Basic for Applications窗口.

2。 点击 插页 > 模块,然后将以下代码粘贴到 模块窗口.

VBA代码:求和一系列单元格中的粗体数字

Function SumBold(WorkRng As Range)
'Update 20220516
Dim Rng As Range
Dim xSum As Double
For Each Rng In WorkRng
    If Rng.Font.Bold Then
        xSum = xSum + Rng.Value
    End If
Next
SumBold = xSum
End Function

3。 然后保存此代码,然后键入此公式 = sumbold(A1:C9) 放入空白单元格,请参见屏幕截图:

文档计数粗体单元格3

4. 然后按 输入 键,则将A1:C9范围内的所有粗体数字相加。 看截图:

文档计数粗体单元格4

请注意:A1:C9 公式中的表示要使用该函数求和粗体单元格的范围,可以根据需要进行更改。


使用 Kutools for Excel 多次单击以对某个范围内的粗体单元格进行计数和求和

Y只需单击几下,您就可以轻松地对范围内的所有粗体单元格进行计数或求和,而无需处理复杂的VBA代码和记住公式。

申请前 Kutools for Excel首先下载并安装.

1.要计算粗体单元格,请选择一个空白单元格以查找结果,然后单击 库工具 > Kutools函数 > 统计与数学 > 计数字体.

要汇总粗体单元格,请单击 库工具 > Kutools函数 > 统计与数学 > 字体粗体。 看截图:

2.在F功能参数 对话框中,在“引用”框中使用您需要计数或求和的粗体单元格指定范围,然后单击 OK 按钮。

现在,将立即在选定的单元格中填充指定范围内所有粗体单元格的计数或求和。 看截图:

  如果您想免费试用(30天)此实用程序, 请点击下载,然后按照上述步骤进行操作。


使用 Kutools for Excel 保持公式单元格引用不变


相关文章:

如何在Excel中识别并选择所有粗体单元格或文本?

最佳办公生产力工具

🤖 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 (22)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello Anthony,
I was struggling with the same problem. For me, the solution ended up being very simple. I noticed I had 4 Modules listed. I removed all of them and then started over with the above instructions. Now it works perfectly.
This comment was minimized by the moderator on the site
I use the function and keep getting the #NAME? error. I am using Excel 365 and Windows11.
This comment was minimized by the moderator on the site
Hello, Anthony

Have you copied and pasted the code into the Module of Microsoft Visual Basic for Applications window in your worksheet? Afetr pasting the code, then, you should enter the formula as you need.

Or you can upload your file here, we can check where the problem is.

Thank you!
This comment was minimized by the moderator on the site
Ma se metto in grassetto nuove celle, la somma non si aggiorna !!!
This comment was minimized by the moderator on the site
Hello Carlo,

Gald to help. After you bold new cells, the sum won't update automatically. But when you double-click the formula cell, then press Enter, the sum will update. Please have a try.

Sincerely,
Mandy
This comment was minimized by the moderator on the site
Hi Mandy,
thanks for your reply,
Yes I know that after double click the sum will uograde.
Is there any way to upgrade automatically the sum ?

Regards
Carlo
This comment was minimized by the moderator on the site
Hello Carlo,

Sorry that I don't have the solution for automatically upgrading the sum. The easiest way I can think of is to press Ctrl + Alt + F9 to recalculate all worksheets in all open workbooks. Have a nice day.

Sincerely,
Mandy
This comment was minimized by the moderator on the site
А если в ячейках числа и текст? надо просуммировать только ячейки с числами жирным шрифтом.
This comment was minimized by the moderator on the site
RE: CountBold formula This formula does not appear to be dynamic. While it works at first pass, if i change the bolded cells the counters do not update unless i re-enter the formula again. Any tips?
This comment was minimized by the moderator on the site
Yea this is the same for me, otherwise it works great. But if this could be solved so it refreshes the count after each cell deselect like other basic counts it would be perfect!
This comment was minimized by the moderator on the site
Dear guys,
The formula won't update if you just change the format of the number cells.
It updates only when you change the cell content.
This comment was minimized by the moderator on the site
I'm using excel for mac 2011. How can I run the code on my system? thanks!
This comment was minimized by the moderator on the site
I copied and pasted code into excel but get #NAME? error. I made sure to enable macros and using excel 2010 version (don't know if that changes anything). Can anyone please help?!
This comment was minimized by the moderator on the site
[quote]I copied and pasted code into excel but get #NAME? error. I made sure to enable macros and using excel 2010 version (don't know if that changes anything). Can anyone please help?!By Maey[/quote] You have to follow the instruction. It says: "Click Insert > Module, and paste the following code in the Module Window", and you have to do exactly so. Make sure you paste the code in the Module Window, not in the Sheet code Window.
This comment was minimized by the moderator on the site
Thank you.. it's working...
This comment was minimized by the moderator on the site
This works a treat. I only have one issue...it doesn't seem to be adding anything after a decimal point. Any help would be greatly appreciated.
This comment was minimized by the moderator on the site
This works perfectly except it doesn't seem to add my decimal places, only adds the whole dollar. If you have a fix for this I would be very grateful.
This comment was minimized by the moderator on the site
Hi Katie, Use the below code, as the sum shows decimal places. Function SumBold(rng As Range) Dim rCell As Range Application.Volatile SumBold = 0 For Each rCell In rng If rCell.Font.Bold Then _ SumBold = SumBold + rCell Next End Function
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations