本文介紹如何按顏色求和與計(jì)數(shù)函數(shù)。
1、求相同顏色單元格個數(shù)CountColor()
FunctionCountColor(colAsRange,countrangeAsRange)AsInteger
DimicellAsRange
Application.Volatile
ForEachicellIncountrange
Ificell.Interior.ColorIndex=col.Interior.ColorIndexThen
CountColor=CountColor+1
EndIf
Nexticell
EndFunction
2、求相同顏色單元格數(shù)值和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--創(chuàng)建--進(jìn)入vb編輯頁面
2、刪除所有內(nèi)容--將以上代碼復(fù)制后粘貼到vb編輯頁面--保存為.xla(加載宏文件)
3、輸入函數(shù)=CountColor(指定顏色的單元格,統(tǒng)計(jì)區(qū)域),






