excel实现按颜色求和与计数函数

本文介绍如何按颜色求和与计数函数。

1、求相同颜色单元格个数CountColor()
FunctionCountColor(colAsRange,countrangeAsRange)AsInteger
DimicellAsRange
Application.Volatile
ForEachicellIncountrange
Ificell.Interior.ColorIndex=col.Interior.ColorIndexThen
CountColor=CountColor+1
EndIf
Nexticell
EndFunction
2、求相同颜色单元格数值和SumColor()
FunctionSumColor(colAsRange,sumrangeAsRange)AsInteger
DimicellAsRange
Application.Volatile
ForEachicellInsumrange
Ificell.Interior.ColorIndex=col.Interior.ColorIndexThen
SumColor=Application.Sum(icell)+SumColor
EndIf
Nexticell
EndFunction
具体操作过成是:
1、工具--宏--输入宏名CountColor--创建--进入vb编辑页面
2、删除所有内容--将以上代码复制后粘贴到vb编辑页面--保存为.xla(加载宏文件)
3、输入函数=CountColor(指定颜色的单元格,统计区域),

office办公软件入门基础教程 » excel实现按颜色求和与计数函数

本文链接:【excel实现按颜色求和与计数函数】https://www.officeapi.cn/35630.html

OFFICE,天天学一点,进步多一点

联系我们