Thomas Kuriakose
Active Member
Respected Sirs,
We copied the below code for counting colored cells with conditional formatting, it works for cells where there is fill color but not when the same cells have conditional formatting.
Kindly let me know how to get this working through VBA.
Please find attached the file for your reference.
Thank you very much,
with regards,
thomas
We copied the below code for counting colored cells with conditional formatting, it works for cells where there is fill color but not when the same cells have conditional formatting.
Code:
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
Kindly let me know how to get this working through VBA.
Please find attached the file for your reference.
Thank you very much,
with regards,
thomas