【问题标题】:How to count cells that only contain the VALUE 0 and not the result of a formula?如何计算仅包含 VALUE 0 而不是公式结果的单元格?
【发布时间】:2013-04-20 14:40:17
【问题描述】:

对于以下工作表:

    A
1   0
2   0 as formula result
3   0
4   0 as formula result
5   0 as formula result
6   blank
7   0

如何只计算输入为 VALUES 的 0 的单元格,而不是计算公式结果为 0 的单元格,即

COUNTIF(A1:A7,0 AS VALUE) = 3

我尝试了以下方法:

COUNTIF(A1:A7,0) = 6

COUNTIF(A1:A7,"0") = 6

【问题讨论】:

  • 请注意,在 Excel 2013 中,您可以使用 FORMULATEXT 函数执行某些操作,如果没有公式,该函数将返回 #N/A
  • 公式结果为空怎么办? +1 或离开

标签: excel excel-formula formula countif


【解决方案1】:

COUNTIF(A1:A7;0) 这对我有用

【讨论】:

  • 这应该是一条评论。
【解决方案2】:

不确定 Excel,但 VBA 具有此功能。所以你可以定义一个小的UDF来实现这个:

Function HasFormula(r as Range) As Boolean
    HasForumla = r.HasFormula
End Function

现在您可以使用 IF 和 COUNT 调用此函数来获取结果。

【讨论】:

    【解决方案3】:

    以下 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
    

    【讨论】:

      【解决方案4】:

      用这个公式填充单元格B1

      =IF(AND(A1=0,ISFORMULA(A1)=FALSE),1,0)
      

      将此公式复制到单元格B2:B7

      对单元格B1:B7 求和,你就会得到你想要的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多