How to track formatting changes
I wrote a user-defined function that sums all cells in a given range that
have the same color fill as the calling cell. The code works great except
when the user changes the fill color of a cell. The formula will not update
because technically no values changed.
How can I get around this?
I am providing the code for others to use.
------------------------------------------------------------------------------------------
Function sumColor(range1 As Range, Optional range2 As Range, Optional range3
As Range, Optional range4 As Range)
sumColor = 0
For Each cell In range1
If cell.Interior.ColorIndex = Application.ThisCell.Interior.ColorIndex
Then
sumColor = sumColor + cell.Value
End If
Next cell
If Not range2 Is Nothing Then
For Each cell In range2
If cell.Interior.ColorIndex =
Application.ThisCell.Interior.ColorIndex Then
sumColor = sumColor + cell.Value
End If
Next cell
End If
If Not range3 Is Nothing Then
For Each cell In range3
If cell.Interior.ColorIndex =
Application.ThisCell.Interior.ColorIndex Then
sumColor = sumColor + cell.Value
End If
Next cell
End If
If Not range4 Is Nothing Then
For Each cell In range4
If cell.Interior.ColorIndex =
Application.ThisCell.Interior.ColorIndex Then
sumColor = sumColor + cell.Value
End If
Next cell
End If
End Function
------------------------------------------------------------------------------------------
Thanks, Pflugs
|