跳至内容
九溪
溪水润知林,滴露启慧心
用户工具
登录
站点工具
搜索
工具
显示页面
过去修订
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您在这里:
Home
»
知识标签
»
app
»
Excel 实现按照单元格和字体颜色计数(Count)与求和(Sum)
您的足迹:
wiki:app:office-excel-count-color-cell
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== Excel 实现按照单元格和字体颜色计数(Count)与求和(Sum) ====== ===== 步骤一 ===== 首先需要启用Visual Basic编辑器,右键单击示例工作表,然后左键单击【查看代码】选项。在Visual Basic编辑器中的工程资源管理器窗口中,右键单击后将鼠标指针移动至插入选项,然后插入一个模块,并将以下代码复制粘贴到代码窗口中,最后关闭Visual Basic编辑器回到Excel工作表操作界面。 代码如下: <code vb script.vb> '计算获得与引用单元格相同底纹颜色的单元格的数量 Function GetCountColorBack(col As Range, countbackrange As Range) As Integer Dim icell As Range Application.Volatile For Each icell In countbackrange If icell.Interior.ColorIndex = col.Interior.ColorIndex Then GetCountColorBack = GetCountColorBack + 1 End If Next icell End Function '计算获得与引用单元格相同底纹颜色的单元格的数值和 Function GetSumColorBack(col As Range, sumbackrange As Range) As Integer Dim icell As Range Application.Volatile For Each icell In sumbackrange If icell.Interior.ColorIndex = col.Interior.ColorIndex Then GetSumColorBack = Application.Sum(icell) + GetSumColorBack End If Next icell End Function '计算获得与引用单元格相同文字颜色的单元格的数量 Function GetCountColorFont(col As Range, countfontrange As Range) As Integer Dim icell As Range Application.Volatile For Each icell In countfontrange If icell.Font.ColorIndex = col.Font.ColorIndex Then GetCountColorFont = GetCountColorFont + 1 End If Next icell End Function '计算获得与引用单元格相同文字颜色的单元格的数值和 Function GetSumColorFont(col As Range, sumfontrange As Range) As Integer Dim icell As Range Application.Volatile For Each icell In sumfontrange If icell.Font.ColorIndex = col.Font.ColorIndex Then GetSumColorFont = Application.Sum(icell) + GetSumColorFont End If Next icell End Function </code> ===== 步骤二 ===== 求相同颜色的单元格数量,需要用到GetCountColorFont函数。函数GetCountColorFont的使用方法:=GetCountColorFont(指定颜色的单元格,统计单元格区域) 参考: - Excel超实用技能,按单元格颜色求和与计数,千万不要错过 https://kuaibao.qq.com/s/20190814A0SZY000?refer=cp_1026 - 在 Excel 中创建自定义函数 https://support.microsoft.com/zh-cn/office/%E5%9C%A8-excel-%E4%B8%AD%E5%88%9B%E5%BB%BA%E8%87%AA%E5%AE%9A%E4%B9%89%E5%87%BD%E6%95%B0-2f06c10b-3622-40d6-a1b2-b6748ae8231f - 如何分别计数[Excel]不同颜色的单元格? https://www.zhihu.com/question/54651422
wiki/app/office-excel-count-color-cell.txt
· 最后更改: 2023/01/03 15:25 由
127.0.0.1
页面工具
显示页面
过去修订
反向链接
回到顶部