I am using the following formula:
Function SumByColor(InputRange As Range, ColorRange As Range) As Double
' returns the sum of each cell in the range InputRange that has the same
' background color as the cell in ColorRange
' example: =SumByColor($A$1:$A$20,B1)
' range A1:A20 is the range you want to sum
' range B1 is a cell with the background color you want to sum
Dim cl As Range, TempSum As Double, ColorIndex As Integer
' Application.Volatile ' this is optional
ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex
TempSum = 0
On Error Resume Next ' ignore cells without values
For Each cl In InputRange.Cells
If cl.Interior.ColorIndex = ColorIndex Then
TempSum = TempSum + cl.Value
End If
Next cl
On Error GoTo 0
Set cl = Nothing
SumByColor = TempSum
End Function
I used this in a spreadsheet I had for 2012 and just copied that same spreadsheet to use for 2013 and now my formula won't work. I remember when I first started using it in 2012, I had to hit some key to run the "macro" or formula but then it started doing it itself. How do I get the formula to start working again? I'm using the same cells/formulas as the old spreadsheet, I just updated the days of the year.
Bookmarks