Summing Cells with a BLUE font (or any other color)

R

RAYMOND KELLY

To all,

I am trying to sum cells that have a specific color.

Here is what I have so far:
Function SumByColor(InRange As Range, WhatColorIndex As Integer)

Dim Rng As Range
Dim OK As Boolean

Application.Volatile True
For Each Rng In InRange.Cells
OK = (Rng.Font.ColorIndex = WhatColorIndex)
If OK And IsNumeric(Rng.Value) Then
SumByColor = SumByColor + Rng.Value
End If
Next Rng

End Function
****Thank you Chip****

When I attempt to use this, I get an error "#NAME?"

Any ideas on what is going wrong?
Thanks.
 
T

Tom Ogilvy

Put the code in a general module (in the vbe, insert=>module). Not in a
module associated with a worksheet, thisworkbook, userform or a class
module.

--
Regards,
Tom Ogilvy

To all,

I am trying to sum cells that have a specific color.

Here is what I have so far:
Function SumByColor(InRange As Range, WhatColorIndex As Integer)

Dim Rng As Range
Dim OK As Boolean

Application.Volatile True
For Each Rng In InRange.Cells
OK = (Rng.Font.ColorIndex = WhatColorIndex)
If OK And IsNumeric(Rng.Value) Then
SumByColor = SumByColor + Rng.Value
End If
Next Rng

End Function
****Thank you Chip****

When I attempt to use this, I get an error "#NAME?"

Any ideas on what is going wrong?
Thanks.
 
F

Frank Kabel

Hi
where do you put this function?. It has to go in a standard module

--
Regards
Frank Kabel
Frankfurt, Germany

To all,

I am trying to sum cells that have a specific color.

Here is what I have so far:
Function SumByColor(InRange As Range, WhatColorIndex As Integer)

Dim Rng As Range
Dim OK As Boolean

Application.Volatile True
For Each Rng In InRange.Cells
OK = (Rng.Font.ColorIndex = WhatColorIndex)
If OK And IsNumeric(Rng.Value) Then
SumByColor = SumByColor + Rng.Value
End If
Next Rng

End Function
****Thank you Chip****

When I attempt to use this, I get an error "#NAME?"

Any ideas on what is going wrong?
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top