繁体   English   中英

计算具有特定填充颜色和像元值的像元数

[英]Count the number of cells with both specific fill color and cell value

我在下面使用代码,但无法正常工作。

Function CountColorValue(CountRange As Range, CountColor As Range, CountVAlue As Range)

  Dim numbers As Long
  Dim Cell As Range

  Set rCell = CountRange

  For Each rCell In CountRange
    If rCell.Interior.ColorIndex = Color Then
      If rCell.Value = Value Then
        numbers = numbers + 1
      End If

      GetColorCount = TotalCount

End Function

谦虚地建议您进入VBE的“工具”►“选项”,然后在“编辑器”属性页上,在“ 要求变量声明”旁边打勾。 这将帮助您避免拼写错误或完全省略所使用变量的名称。

Function CountColorValue(CountRange As Range, CountColor As Range, CountValue As Range)

    Dim iNumbers As Long
    Dim rCell As Range

    For Each rCell In CountRange
        If rCell.Interior.ColorIndex = CountColor.Interior.ColorIndex Then
            If rCell.Value2 = CountValue.Value2 Then
                iNumbers = iNumbers + 1
            End If
        End If
    Next rCell

    CountColorValue = iNumbers

End Function

似乎您正在尝试将两个紧密相关的功能融合在一起,但是如果没有正确的变量声明和赋值,就无法在一个功能中使用另一个功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM