using excel 2013
I found this code and this formula on the net. But it does not calculate automatically. What I am trying to do, as I color cells in a row one specific color i'd like the number of colored cells show up in cell D4.
Here is the code and formula i found but as i said, it is automatically counting.
the 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
the formula:
i tired both of these:
=colorfunction(A1,A1:D7,FALSE)
=colorfunction(A1,A1:D7,TRUE)
I found this code and this formula on the net. But it does not calculate automatically. What I am trying to do, as I color cells in a row one specific color i'd like the number of colored cells show up in cell D4.
Here is the code and formula i found but as i said, it is automatically counting.
the 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
the formula:
i tired both of these:
=colorfunction(A1,A1:D7,FALSE)
=colorfunction(A1,A1:D7,TRUE)