fiberboysa
Board Regular
- Joined
- Apr 25, 2012
- Messages
- 106
- Office Version
- 365
- Platform
- Windows
Hi All,
I have a sheet in which I need to sum values based on condition that these cells need to be highlighted/filled with a color and it should be visible in filter.
I found following code which is working for Highlighted/filled cells but it is summing up all visible and hidden cells...
Please can anyone help me to modify this code or give me a new code to sum Highlighted Visible cells only?
I have a sheet in which I need to sum values based on condition that these cells need to be highlighted/filled with a color and it should be visible in filter.
I found following code which is working for Highlighted/filled cells but it is summing up all visible and hidden cells...
VBA Code:
Function SumByColor(CellColor As Range, rRange As Range)
Dim cSum As Long
Dim ColIndex As Integer
ColIndex = CellColor.Interior.ColorIndex
For Each cl In rRange
If cl.Interior.ColorIndex = ColIndex Then
cSum = WorksheetFunction.Sum(cl, cSum)
End If
Next cl
SumByColor = cSum
End Function
Please can anyone help me to modify this code or give me a new code to sum Highlighted Visible cells only?