ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Summing Cells with a BLUE font (or any other color) (https://www.excelbanter.com/excel-programming/311368-summing-cells-blue-font-any-other-color.html)

RAYMOND KELLY September 24th 04 06:48 PM

Summing Cells with a BLUE font (or any other color)
 
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.
--
RAYMOND KELLY

Tom Ogilvy September 24th 04 06:57 PM

Summing Cells with a BLUE font (or any other color)
 
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

"RAYMOND KELLY" wrote in message
...
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.
--
RAYMOND KELLY



Frank Kabel September 24th 04 06:59 PM

Summing Cells with a BLUE font (or any other color)
 
Hi
where do you put this function?. It has to go in a standard module

--
Regards
Frank Kabel
Frankfurt, Germany

"RAYMOND KELLY" schrieb im Newsbeitrag
...
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.
--
RAYMOND KELLY



All times are GMT +1. The time now is 12:07 AM.

Powered by vBulletin® Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
ExcelBanter.com