Function AverageCellsByBackColor(rData As Range, cellRefColor As Range)
Dim indRefColor As Long
Dim cellCurrent As Range
Dim sumRes
Dim i As Long
sumRes = 0
indRefColor = cellRefColor.CellS(1, 1).Interior.ColorIndex
For Each cellCurrent In rData
If indRefColor = cellCurrent.Interior.ColorIndex Then
sumRes = WorksheetFunction.Sum(cellCurrent, sumRes)
i = i + 1
End If
Next cellCurrent
AverageCellsByBackColor = sumRes / i
End Function