第4个回答 2010-01-29
用宏吧:
Alt+F11进入VBA,单击菜单“插入——》模块”,在模块1代码窗口输入:
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
此时 表中出现自定义函数Countcolor()
将D1背景改为需要计数的单元格颜色(如:红色)
公式写成Countcolor(D$1,$A$1:$A$5),结果就是2.
如果单元格内不是字符而是数字求和,则需要将上述宏内的Count改为Sum。