Ken Hudson
New Member
- Joined
- Sep 10, 2007
- Messages
- 46
I had previously used the following function to count the number of cells with a certain interior cell color. It does not seem to work now.
Can someone tell me what the problem might be?
Formula in cell A11:
=CountRedBYCOLOR(A1:A10,3,TRUE)
Can someone tell me what the problem might be?
Formula in cell A11:
=CountRedBYCOLOR(A1:A10,3,TRUE)
Code:
Function CountRedByColor(InRange As Range, WhatColorIndex As Integer, Optional OfText As Boolean = False) As Double
Dim Rng As Range
Dim OK As Boolean
Dim RedCt As Integer
RedCt = 0
Application.Volatile True
For Each Rng In InRange.Cells
If OfText = True Then
If Rng.Interior.ColorIndex = WhatColorIndex Then
RedCt = RedCt + 1
End If
End If
Next Rng
CountRedByColor = RedCt
End Function