如何在excel中统计相同颜色单元格的数量?

如题所述

在excel中统计相同颜色单元格的数量,用VBA代码处理吧。

    第一步,在VBA编辑器中插入新模块。

    第二步,把下面的代码复制到模块中。创建新函数CColor.

    代码:

Function CColor(Crange as range,Col as range)

Dim n as range

application.Volatile

For each n in crange

If n.Interior.ColorIndex = Col.Interior.ColorIndex

CColor = CColor +1

End if

Next n

End Function

    第三步,使用函数。数据在A1:A10,统计放B1,B1=CCOLOR(A1:A10,A1).

    本例中,公式统计A1:A10区域中与A1单元格颜色一样的数量。

温馨提示:答案为网友推荐,仅供参考
相似回答