VBA统计黑色单元格函数偶尔计数异常问题求助
VBA统计黑色单元格函数偶尔计数异常问题求助
各位大佬好,我最近在做KPI表单的提交率统计,需求是计算已提交分数的占比,要排除空单元格和被涂黑的单元格。我先是借鉴了别人的代码然后做了调整,现在遇到一个诡异的问题:CountBlack函数有时候会莫名其妙多统计2个黑色单元格,实在找不到原因,想请大家帮忙看看!
我的需求逻辑是这样的:
- 用
CountBlack统计涂黑的单元格数量 - 用
CountAll统计选中区域的总单元格数 - 再结合
COUNTA()计算有效单元格的占比
但现在CountBlack偶尔会多算2个,下面是我的代码:
Function CountBlack(range_data As Range) As Long Dim datax As Range CountBlack = 0 For Each datax In range_data If datax.Interior.ColorIndex = 1 Then CountBlack = CountBlack + 1 ' adds 1 for each that meets criteria End If Next datax End Function Function CountAll(range_data As Range) As Long Dim datax As Range CountAll = 0 For Each datax In range_data CountAll = CountAll + 1 'adds one for each counted Next datax End Function
(附:问题对应的表格截图)
备注:内容来源于stack exchange,提问作者Jack Johnson
相关产品推荐
相关产品推荐

