我有一个countcolour(VB脚本)结果,如何在该结果中获得countif结果

时间:2017-06-12 21:54:32

标签: excel vb.net multiple-results

我在VB中使用了一个= countcolour脚本,结果我得到了结果。例如," = countcolour(a1:a10,b1)" b1正在说绿色,结果是6个绿色单元格。 我想知道的是,如果有一个单元格值为" G"在" A1:A10"中随机输入,我怎样才能计算" G"在countcolour结果中?

1 个答案:

答案 0 :(得分:0)

我并不完全确定我了解您所追求的内容,但如果它相当于COUNTIFS工作表公式,则以下代码将起作用:

Sub SumCountByConditionalFormat()
Dim refColor As Long
Dim rng As Range
Dim countRng As Range
Dim countCol As Long

Set countRng = Sheet1.Range("$A$1:$A$10")

    refColor = Sheet1.Range("$B$1").DisplayFormat.Interior.Color
    For Each rng In countRng
        If rng.DisplayFormat.Interior.Color = refColor And rng.Value = "g" Then
            countCol = countCol + 1
        End If
    Next
    MsgBox countCol

End Sub