Public Function SumColor(rngData As Range, intColor As Integer) As Double
Dim rngCell As Range
Dim dblSum As Double
' Interior.ColorIndex = 3 'red
' Interior.ColorIndex = 5 'blue
' Interior.ColorIndex = 4 'green
' Interior.ColorIndex = 6 'yellow
' Interior.ColorIndex = 44 'gold
Application.Volatile
For Each rngCell In rngData
If rngCell.Interior.ColorIndex = intColor Then
On Error Resume Next
If Err.Number = 0 Then
If Application.WorksheetFunction.Type(rngCell.Value) = 1 Then
dblSum = dblSum + rngCell.Value
End If
Else
Err.Clear
End If
End If
Next
SumColor = dblSum
End Function
|