PDA

View Full Version : Adding values based on cell colour



Stewie
2012-08-09, 11:21 AM
Hi, I am trying to calculate value of cells with a specific colour - red.


I understand excel uses vba for this function - can you advise please, i have no experience of using code,


Regards,
Stewie

vijaydm
2012-08-12, 07:50 AM
Hi

Please use below UDF
based on cells..
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)


Application.Volatile
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

vijaydm
2012-08-12, 07:53 AM
any doubts .. please send me the attachment i will help u