I have used the following code to sum color using UDF in Excel, but the result I get is zero.
See my code below as well as sample data. It would be appreciated if someone could assist me
Function SumColor(rColor As Range, rSumRange As Range)
Dim rCell As Range
Dim iCol As Integer
Dim vResult
iCol = rColor.Interior.ColorIndex
For Each rCell In rSumRange
If rCell.Interior.ColorIndex = iCol Then
vResult = vResult + 1
End If
Next rCell
CountColor = vResult
End Function
See my code below as well as sample data. It would be appreciated if someone could assist me
Function SumColor(rColor As Range, rSumRange As Range)
Dim rCell As Range
Dim iCol As Integer
Dim vResult
iCol = rColor.Interior.ColorIndex
For Each rCell In rSumRange
If rCell.Interior.ColorIndex = iCol Then
vResult = vResult + 1
End If
Next rCell
CountColor = vResult
End Function
Summing Colors.xltm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | 125.25 | |||||
2 | 185.95 | |||||
3 | 106.75 | |||||
4 | 103.75 | |||||
5 | 99.85 | |||||
6 | ||||||
7 | 0 | |||||
8 | ||||||
Sheet1 |