I currently have this, but don't know how to add it to sum by both colour and another column. Assuming the numbers are all coloured by their status, I need to sum based on that as well as the category in column A - how do I adjust the VBA code below to allow for that?
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
Category | Month A | Month B |
A | 100 | 100 |
B | 2000 | 200 |
A | 100 | 300 |
B | 200 | 400 |
B | 100 | 500 |
B | 300 | 600 |
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