# Sum based on font color

1. ## Sum based on font color

Is there a function which can sum up all the cells in a column where the
contents of the cell are in pink color.

Pls help.

Thanks  Register To Reply

2. try:

Function SumByFontColor(ColorNum)

set rng = ActiveSheet.UsedRange.rows
For each c in rng
If c.font.colorindex=ColorNum then
s = s + c.value
End if
SumByColorFont= s

End Function  Register To Reply

3. try:

Function SumByFontColor(ColorNum)

Set rng = ActiveSheet.UsedRange.Rows
rng.Select
For Each c In Selection
If c.Font.ColorIndex = ColorNum Then
s = s + c.Value
MsgBox s
End If
Next
SumByFontColor = s

End Function  Register To Reply

4. ## RE: Sum based on font color

something along these lines to get you started:

Option Explicit
Enum eColor
Pink = 13408767
End Enum
Function ColorSum(Source As Range) As Double
Dim total As Double
Dim cell As Range
For Each cell In Source
With cell
If .Font.Color = eColor.Pink Then
total = total + .Value
End If
End With
Next
ColorSum = total
End Function

Enhancements:
1) see if you can make the color a parameter
2) add a check to ensure that a cell has a legitimate value befor totalling

works as is though.

"mario" wrote:

> Is there a function which can sum up all the cells in a column where the
> contents of the cell are in pink color.
>
> Pls help.
>
> Thanks  Register To Reply

5. ## Re: Sum based on font color

See http://www.xldynamic.com/source/xld.ColourCounter.html

--

HTH

RP
(remove nothere from the email address if mailing direct)

"mario" <mario@discussions.microsoft.com> wrote in message
news:1993969A-9B36-4758-8A4C-B4C3DD2E3DE0@microsoft.com...
> Is there a function which can sum up all the cells in a column where the
> contents of the cell are in pink color.
>
> Pls help.
>
> Thanks  Register To Reply