回复 lgpoo 的帖子
Excel 本身没有这个功能,可用以下办法实现:
打开你的工作表:点工具--宏--Visual Basic 编辑器,在左边最上一行点右键--插入--模块,然后在打开的编辑框中粘贴以下代码:
Function CountColor(col As Range, countrange As Range) As Integer
Dim icell As Range
Application.Volatile
For Each icell In countrange
If icell.Interior.ColorIndex = col.Interior.ColorIndex Then
CountColor = CountColor + 1
End If
Next icell
End Function
Function SumColor(col As Range, sumrange As Range) As Integer
Dim icell As Range
Application.Volatile
For Each icell In sumrange
If icell.Interior.ColorIndex = col.Interior.ColorIndex Then
SumColor = Application.Sum(icell) + SumColor
End If
Next icell
End Function
然后关闭,反回到工作表,点击--工具-选项--安全性--宏安全性--安全级选--低--确定
保存关闭工作表,然后再打开,这时就可以用了
用法:
按颜色求和:sumcolor(颜色示列格,求和区域或列);按颜色计数:countcolor(颜色示列格,求和区域或列)
例如:要求和从a1到a10这个区域内的红色格,
=sumcolor($a$1,$a$1:$A$10)
计数:countcolor($a$1,$a$1:$A$10)
注意:$a$1 必须是红色格,这是定义颜色的,你也可以设成其它格,但必须是你要求和的颜色
ok!有问题可以留言。