MissMaggie
New Member
- Joined
- May 29, 2017
- Messages
- 7
Hello,
I am trying to figure out why the code won't work for counting colored cells. I think it should be that when I click in a blank cell and type =ColorFunction then I can select the cell with the background color I want to count, the range, and False (true should give the sum) Not sure what I am doing wrong as far as user error. Thank you!
-Maggie
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
End If
ColorFunction = vResult
End Function