Search This Blog

Monday 14 June 2010

Excel: Sum cells based on colour

'Sums cells based on a specified fill color.

'''''''''''''''''''''''''''''''''''''''

 Dim rCell As Range

 Dim iCol As Integer

 Dim vResult



 iCol = rColor.Interior.ColorIndex



  For Each rCell In rSumRange

   If rCell.Interior.ColorIndex = iCol Then

    vResult = WorksheetFunction.Sum(rCell) + vResult

   End If

  Next rCell



 SumColor = vResult

End Function