Excel - ignore red numbers when totaling rows

G

Guest

Excell 2002 SP3 - When totaling up my rows and columns I want Excel to ignore
any numbers I make red. ( I still want to see them - just not have them
included in the totals )

Thank you,

Chris
 
C

Chip Pearson

Chris,

You can do this only with code:

Function SumExceptColor(InputRange As Range, ExcludeCI As Integer, _
OfText As Boolean) As Double

Dim Rng As Range
Dim Total As Double
For Each Rng In InputRange.Cells
If IsNumeric(Rng.Value) = True Then
If OfText = True Then
If Rng.Font.ColorIndex <> ExcludeCI Then
Total = Total + Rng.Value2
End If
Else
If Rng.Interior.ColorIndex <> ExcludeCI Then
Total = Total + Rng.Value2
End If
End If
End If
Next Rng
SumExceptColor = Total

End Function

In this function, InputRange is the range to sum. ExcludeCI is the
ColorIndex to exclude from the summation (Red = 3), OfText indicates whether
to look at the color of text (if OfText = True) or the background (if OfText
= False) of each cell.

You can call this function with

=SumExceptColor(A1:A10,3,TRUE)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting LLC
www.cpearson.com
(email on the web site)
 

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