Hi All,
I'd like to modify this VB function (originally posted elsewhere) to count cells that match the font color rather than the background color. I realize there are other ways to count cells of a certain font color, but I'd really love to see the differences between this code and the final code so I can understand this better (and hopefully not have to post questions too often!).
This works pretty simply, returning the total cells that match the highlight (background) color: ColorCount(range,cell_to_compare)
Function CountColor(rColorRange As Range, rColorIndex As Range) As Long
Dim rCell As Range 'range for loop.
Dim lColor As Long 'Index of the cells color we want to count.
Dim lColorCount As Long 'Counter
lColorCount = 0 'Initialise counter
lColor = rColorIndex.Interior.ColorIndex 'Set color to count
'Loop through each cell in the range
For Each rCell In rColorRange
If rCell.Interior.ColorIndex = lColor Then lColorCount = lColorCount + 1
Next rCell
'Return count to function
CountColor = lColorCount
End Function
Any thoughts?
Thanks in advance.
Bookmarks