Forum Discussion
dickcarey460gmailcom
Feb 27, 2023Copper Contributor
use sumif function when criteria is cell hihlighted with a color highlight
I want to use sumif function to add a column of numbers when criteria is a fill color in the cells. How do I do this.
HansVogelaar
Aug 10, 2024MVP
The earlier questions in this discussion were about summing whole numbers. If you want to sum numbers with decimals, change the return type of the function from Long to Double:
Function SumByColor(ARange As Range, ColorCell As Range) As Double
Dim ACell As Range
Application.Volatile
For Each ACell In ARange
If ACell.Interior.Color = ColorCell.Interior.Color Then
SumByColor = SumByColor + Val(ACell.Value)
End If
Next ACell
End Functionjeremyc740
Aug 10, 2024Copper Contributor
That would be it! I've had very little exposure to creating macros and typing code, so I knew it had to be something with that when my formatting within the sheet was accurate. Greatly appreciated HansVogelaar!