人气 5150

[Excel技巧] Excel 统计相同颜色的单元格及合计 [复制链接]

谁于争锋 2017-9-22 16:49:10
在Excel文件中,有时需要在不同的情况下用不同的颜色标记单元格且录入相应的数据。可更加方便直观地看到该数据的情况如迟到的标记为红色,早退标记为蓝色。迟到的时间不同,所扣的款也不同。那么我们如何统计单元格的颜色个数和汇总相同单元格颜色的值
如下图所示

1506070681108569.jpg

1506070681108569.jpg

详细vba代码: '统计相同单元格的个数
FunctionCountColor(colAsRange,countrangeAsRange)AsInteger
DimicellAsRange
Application.Volatile
ForEachicellIncountrange
Ificell.Interior.ColorIndex=col.Interior.ColorIndexThen
CountColor=CountColor+1
EndIf
Nexticell
EndFunction
'统计相同颜色单元格的合计值
FunctionSumColor(colAsRange,sumrangeAsRange)AsInteger
DimicellAsRange
Application.Volatile
ForEachicellInsumrange
Ificell.Interior.ColorIndex=col.Interior.ColorIndexThen
SumColor=Application.Sum(icell)+SumColor
EndIf
Nexticell
EndFunction
其中:col参数为:指定颜色的单元格,countrange和sumrange 参数为:统计区域
设计方法:1.vbe窗口,插入模块-键入代码2.在窗口调用代码,如单元格=CountColor(K1,H1:H10)
您需要登录后才可以回帖 登录 | 立即注册

QQ|手机版|精益人 ( 沪ICP备19004111号-1 )

GMT+8, 2024-5-18 23:46 , Processed in 0.220687 second(s), 22 queries .

Powered by Lean.ren X3.5 Licensed  © 2001-2030 LEAN.REN