ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   need help with countIF and CountByColor functions~~ (https://www.excelbanter.com/excel-worksheet-functions/10326-need-help-countif-countbycolor-functions%7E%7E.html)

Geni Slaughter

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!!


All times are GMT +1. The time now is 11:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com