WoodsterCorp.com - Count Colours Routine
DataFill Routine Open File Count Colours

Count Colours Routine

The following snippet is useful for counting colours, particularly if they have been assigned the colour from a conditional format.

In VB enter the following:

Function colornumber(myvar As Range)
Colornumber = myvar.Interior.ColorIndex
End Function

Function colorcount(myvar As Range, ColVar As Long)
For Each cell In myvar
     If cell.Interior.ColorIndex = ColVar Then colorcount = colorcount + 1
Next
End Function

In sum line

=colorcount(B5:B14,colournumber(B8))

B5:B14 is the range to be counted.
B8 is a reference cell of the colour to be counted (best to create a cell with this colour).