Sum only formatted cells

A

Annette Stephens

I'm trying to add cells that have a yellow fill colour in a column that
contains filled ad unfilled cells, I'm sure I've read this somewhere but
can't find it, any help would be greatly appreciated.

JMS
 
B

Bernard REY

Annette Stephens wrote :
I'm trying to add cells that have a yellow fill colour in a column that
contains filled ad unfilled cells, I'm sure I've read this somewhere but
can't find it, any help would be greatly appreciated.

You can do this with a macro. Her's an eample of how you can have the sum of
cells filled in red (colorindex = 3) in a selected range, displayed in A1:

Sub SumIt()
Dim c As Range: Dim MySum As Double
For Each c In Selection ' or in Range("B1:B29"), or a named range
If c.Interior.ColorIndex = 3 Then
MySum = MySum + c.Value
End If
Next c
Range("A1") = MySum
End Sub

If red isn't just your favorite color, search the helpfile for "ColorIndex"
to find the index corresponding to your favorite ;)
 

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