-1

我在 VB 中使用了 =countcolour 脚本,最终得到了结果。例如,“=countcolour(a1:a10,b1)” b1 可以说是绿色,结果是 6 个绿色单元格。我想知道的是,如果在“A1:A10”中随机输入了“G”的单元格值,那么我该如何计算计数结果中的“G”?

4

1 回答 1

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
于 2017-06-12T23:21:42.080 回答