I'm working on a project for work. I want to be able to find the average for a range of data based on the fill color of the cell. So I can have one formula to show the average of all the purple cells, another for the average of all the green cells, etc. I found a thing that works for finding the sum, but I don't know enough to change it to find the average. The code (?) for the sum is below. Any help would be appreciated!
Function SumByColor(CellColor As Range, SumRange As Range)
Dim ICol As Integer
Dim TCell As Range
ICol = CellColor.Interior.ColorIndex
For Each TCell In SumRange
If ICol = TCell.Interior.ColorIndex Then
SumByColor = SumByColor + TCell.Value