View Single Post
  #1   Report Post  
Geni Slaughter
 
Posts: n/a
Default need help with countIF and CountByColor functions~~

OK, I got this code from a previous post, and it works great.
Now what I want to do is have the function check to see if the cell has a
"D" in it or not. If it does, continue and add to the count if the color
matches. If not, go on to the next cell.
Make sense???
I tried to edit this myself and could not.
Here is the function code I'm using:

Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
'
' This function return the number of cells in InRange with
' a background color, or if OfText is True a font color,
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True

For Each Rng In InRange.Cells
If OfText = True Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng

End Function


So I want it to test the cell first for the letter D and then see if it's
the certain color.

Thanks for your help!!