excel2003中如何根据指定单元格颜色来计数

来源:百度知道 编辑:UC知道 时间:2024/05/29 22:07:22
excel2003中如何根据指定单元格颜色来计数?类似countif功能的 比如我需要确认一张表格里 散乱分布的红色单元格的个数 然后把这个数放到指定位置,请给出完整公式或宏 先谢谢了!

添加模块,复制代码
Function countcolour(target As Range)
Dim cell As Range
Dim cnt As Integer
cnt = 0
For Each cell In target
If cell.Interior.ColorIndex = 3 Then cnt = cnt + 1
Next cell
countcolour = cnt
End Function
在单元格中引用countcolour即可。如在F1中输入=countcolour(A1:D5)就是统计A1到D5中红色单元格的个数.注意是单元格颜色,不是字体颜色.