I have a spreadsheet of data that has been categorized by cell background color. I need to find the total sum and total averages for various data types on the spreadsheet. Right now, I have a macro set up that sums data based on the cells background color, but I can't figure out how to average cells based on color so I've been manually doing that. Is there a way I can use a macro to take the sum of certain data types and average other data types on the same tab? Below is the current macro I'm using:
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function
I'm new to macros, so any and all help/advice is appreciated!! Thank you!
Bookmarks