如何计算阴影并大于特定值的像元

时间:2019-08-30 04:30:41

标签: excel vba

我有一系列希望计算的阴影单元格,但我也想计算那些阴影大于零的单元格

我找到了一些代码,该代码编写了根据颜色对单元格进行计数的公式,但是我试图对其进行修改以添加其他条件。我尝试将AND命令添加到公式中以提供其他条件。

Function CountColorIf(rSample As Range, rArea As Range) As Long

Dim rAreaCell As Range
Dim lMatchColor As Long
Dim lCounter As Long

lMatchColor = rSample.Interior.Color
For Each rAreaCell In rArea
    If rAreaCell.Interior.Color = lMatchColor And Cells.Value > "0" Then
        lCounter = lCounter + 1
    End If
Next rAreaCell
CountColorIf = lCounter
End Function

我在现有代码中添加了And Cells.Value>“ 0”

在搜索每个“ rAreaCell”时,是否可以不添加一个AND来标识它是否大于0?

1 个答案:

答案 0 :(得分:0)

您需要检查的单元格是rAreaCell,您不能使用单元格

If rAreaCell.Interior.Color = lMatchColor And rAreaCell.Value > "0" Then