请需要您的帮助来计算指定不同颜色的单元格值。
在一张纸上,一些单元格用红色填充,一些单元格用蓝色填充,一些单元格用绿色填充。输出应分别为红色细胞计数、蓝色细胞计数和绿色细胞计数。
这是我尝试过的:
Function CountByColor(InputRange As Range, ColorRange As Range) As Long
Dim cl As Range
TempCount As Long
ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex TempCount = 0
For Each cl In InputRange.Cells
If cl.Interior.ColorIndex = ColorIndex
Then
TempCount = TempCount + 1
End If
Next cl
Set cl = Nothing CountByColor = TempCount
End Function