M
Marc.
Hi. Posted something similar yesterday, and was confused
as hell by the response. Have since visinted
cpearson.com, and found an example, but as I try to
implement it, I keep getting a #name? error, no matter
what I try.
Here is what I want.
I want to add the values of cells within a range that do
not have a background color.
Here is what was suggested:
Function SumByColor(InRange As Range, WhatColorIndex As
Integer, _
Optional OfText As Boolean = False) As Double
'
' This function return the SUM of the values of cells in
' InRange with a background color, or if OfText is True a
' font color, equal to WhatColorIndex.
'
Dim Rng As Range
Dim OK As Boolean
Application.Volatile True
For Each Rng In InRange.Cells
If OfText = True Then
OK = (Rng.Font.ColorIndex = WhatColorIndex)
Else
OK = (Rng.Interior.ColorIndex = WhatColorIndex)
End If
If OK And IsNumeric(Rng.Value) Then
SumByColor = SumByColor + Rng.Value
End If
Next Rng
End Function
**AND I PASTED the following text in the cell where I
wanted the result.
=SUMBYCOLOR(J5:J30),0,FALSE) where I want cells that do
not have a color (assuming it is 0, also tried with every
number from 1-20) and False, because it is the background
I want, not the font.
Any help would be appreciated. If you have an easier
method, I would appreciate that too.
as hell by the response. Have since visinted
cpearson.com, and found an example, but as I try to
implement it, I keep getting a #name? error, no matter
what I try.
Here is what I want.
I want to add the values of cells within a range that do
not have a background color.
Here is what was suggested:
Function SumByColor(InRange As Range, WhatColorIndex As
Integer, _
Optional OfText As Boolean = False) As Double
'
' This function return the SUM of the values of cells in
' InRange with a background color, or if OfText is True a
' font color, equal to WhatColorIndex.
'
Dim Rng As Range
Dim OK As Boolean
Application.Volatile True
For Each Rng In InRange.Cells
If OfText = True Then
OK = (Rng.Font.ColorIndex = WhatColorIndex)
Else
OK = (Rng.Interior.ColorIndex = WhatColorIndex)
End If
If OK And IsNumeric(Rng.Value) Then
SumByColor = SumByColor + Rng.Value
End If
Next Rng
End Function
**AND I PASTED the following text in the cell where I
wanted the result.
=SUMBYCOLOR(J5:J30),0,FALSE) where I want cells that do
not have a color (assuming it is 0, also tried with every
number from 1-20) and False, because it is the background
I want, not the font.
Any help would be appreciated. If you have an easier
method, I would appreciate that too.