在Excel中统计相同颜色单元格的数量,需要先编辑自定义函数,然后,再使用此自定义函数来统计。方法如下:
自定义函数名称为CountColor,代码内容如下:
Function CountColor(Countrange as range,Col as range)
Dim n As Range
Application.Volatile
For Each n In Countrange
If n.Interior.ColorIndex = Col.Interior.ColorIndex Then
CountColor =CountColor + 1
End If
Next n
End Function