This is my first request, so sorry if something is incorrect.
I’m working on Excel 2019 and created a custom function:
' Color & Sum
Function ContColor(InputRange As Range) As Double
Application.Volatile
Dim cell As Range
Dim sum As Double
Dim colorPD As Long
sum = 0
colorPD = RGB(153, 255, 102) ' My Color
For Each cell In InputRange
If cell.Interior.Color = colorPD Then
sum = sum + cell.Value
End If
Next cell
ContColor = CLng(sum)
End Function
Now, I would like to change the optional colorPD
to a default color like this:
Function ContColor(InputRange As Range, Optional colorPd As Long = RGB(153, 255, 102)) As Double
transforming the function like this:
Function ContColor(InputRange As Range, Optional colorPd As Long = RGB(153, 255, 102)) As Double
Application.Volatile
Dim cell As Range
Dim sum As Double
sum = 0
For Each cell In InputRange
If cell.Interior.Color = colorPD Then
sum = sum + cell.Value
End If
Next cell
ContColor = CLng(sum)
End Function
But I get error. Someone help me?
New contributor
Faber is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.