-1

I have used a =countcolour script in VB and I ended up with a result. Example, "=countcolour(a1:a10,b1)" b1 being lets say green and the result is 6 green cells. What I would like to know is if there was a cell value of "G" entered in at random across the "A1:A10", how can I then calculate the "G" within the countcolour result?

Loudy
  • 1

1 Answers1

0

Not absolutely sure I understand what you're after, but if it's the equivalent of a COUNTIFS worksheet formula, the following code will work:

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