请帮助您根据不同颜色的指定计算单元格值 。
在一张工作表中,有些单元格填满了“强度”颜色 强度”、一些单元格填满了“强度”蓝色 强度”、一些单元格填满了“强度”绿色 强度”。输出应是单元格计红颜色、单元格计蓝色和单元格计绿颜色。
这就是我曾经尝试过的:
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