excel中如何统计含有某种颜色的单元格的数量?

如题所述

假设这些单元格在一列,选中第一个待统计颜色的单元格,同时按alt和f11,右键点左边窗口的sheet1,在右边新出来的窗口粘贴如下代码:
sub
test()
dim
i,
j,
counter
as
integer
i
=
selection.interior.colorindex
counter
=
1
for
j
=
1
to
1000
selection.offset(1,
0).select
if
selection.interior.colorindex
=
i
then
counter
=
counter
+
1
next
j
msgbox
counter
end
sub
然后按f5,完成
如果行数比较多,把上面的1000改了。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-11-29
假设这些单元格在一列,选中第一个待统计颜色的单元格,同时按Alt和F11,右键点左边窗口的Sheet1,在右边新出来的窗口粘贴如下代码:Sub
test()Dim
i,
j,
Counter
As
Integer
i
=
Selection.Interior.ColorIndex
Counter
=
1
For
j
=
1
To
1000
Selection.Offset(1,
0).Select
If
Selection.Interior.ColorIndex
=
i
Then
Counter
=
Counter
+
1Next
jMsgBox
CounterEnd
Sub然后按F5,完成
相似回答