You need to replace the Color Numbers
Select Case UCase$(myColor)
Case "BLUE": ColorNum = 13998939
Case "GREEN": ColorNum = 4697456
Case "AMBER": ColorNum = 49407
Case "RED": ColorNum = 255
End Select
You could obtain color number:
1 Select the Colored cell that you want to get Color Number
2 Open VBE(Visual Basic Editor) Alt + F11
3 GoTo [View] - [ImmediateWindow]
4 type
?ActiveCell.Interior.Color
Then hit Enter key
It will give you color number that you want.
But this is not a smart way.
I would prefer to get the color from cell in the function like this
In cell B22:
=SumCatCor($A22,$A$4:$M$18,B$21)
Where B21 (Header) has colored like attached.
Function SumCatCor(myCategory, rng As Range, ref As Range) As Double
Dim r As Range, myColor As Long, i As Long
Application.Volatile
myColor = ref.Interior.Color
For i = 1 To rng.Rows.Count
If rng.Cells(i, 1).Value = myCategory Then
For Each r In rng.Rows(i).Cells
If r.Interior.Color = myColor Then SumCatCor = SumCatCor + Val(r.Value)
Next
End If
Next
End Function
Bookmarks