对于以下工作表:
A
1 0
2 0 as formula result
3 0
4 0 as formula result
5 0 as formula result
6 blank
7 0
如何仅计算0
输入为 VALUES 的单元格而不是0
计算公式结果的单元格,即
COUNTIF(A1:A7,0 AS VALUE)
= 3
我尝试了以下方法:
COUNTIF(A1:A7,0)
= 6
COUNTIF(A1:A7,"0")
= 6
对于以下工作表:
A
1 0
2 0 as formula result
3 0
4 0 as formula result
5 0 as formula result
6 blank
7 0
如何仅计算0
输入为 VALUES 的单元格而不是0
计算公式结果的单元格,即
COUNTIF(A1:A7,0 AS VALUE)
= 3
我尝试了以下方法:
COUNTIF(A1:A7,0)
= 6
COUNTIF(A1:A7,"0")
= 6
COUNTIF(A1:A7;0) 这对我有用
不确定 Excel,但 VBA 具有此功能。所以你可以定义一个小的UDF来实现这个:
Function HasFormula(r as Range) As Boolean
HasForumla = r.HasFormula
End Function
现在您可以使用 IF 和 COUNT 调用此函数来获取结果。
以下 VBA 定义的函数将计算区域中具有零的单元格的数量。
Function CountZeros(rng As Range) As Long
Dim cell As Range
CountZeros = 0
For Each cell In rng
If (cell = 0) And (IsEmpty(cell) = False) And Not (HasFormula(cell)) Then
CountZeros = CountZeros + 1
End If
Next
End Function
B1
用这个公式填充单元格:
=IF(AND(A1=0,ISFORMULA(A1)=FALSE),1,0)
将此公式复制到单元格B2:B7
求和单元格B1:B7
,你会得到你想要的。