Goal:
I found this in searching for a formula that could count shaded cells based on their color and it worked great, but if I merge cells it will apply the cell color to them and thus throw off my count. How can I count the cell if its yellow, but ignore if its yellow and blank? I am using VBA and Excel 2016. Thank you for any help provided.
Appearance:
Module:
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
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function
I found this in searching for a formula that could count shaded cells based on their color and it worked great, but if I merge cells it will apply the cell color to them and thus throw off my count. How can I count the cell if its yellow, but ignore if its yellow and blank? I am using VBA and Excel 2016. Thank you for any help provided.
Appearance:
Module:
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
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function