View Single Post
  #2   Report Post  
Old May 11th 04, 10:03 AM posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Counting/summing cells based on background color

Nan

The following is one way of achieving what you want but
may be slow if you are interrogating lots of cells.

The macro below uses a loop to "visit" every cell in a
column until it finds a blank cell (so you may need to
modify this if the data you are investigating is not
contiguous). Having set MySum to zero before processing,
everytimeit enters a cell where the background colour is,
in this example, 36 (you need to use the colour code you
are searching for) AND the value of the data is greater
than zero, it increments the running total in MySum before
moving to the next cell below until a blank is encountered.

Hope this helps.


Sub SumOnColour()
MySum = 0
While ActiveCell.Value < ""
If ActiveCell.Interior.ColorIndex = 36 And
ActiveCell.Value 0 Then
MySum = MySum + ActiveCell.Value
End If
ActiveCell.Offset(1, 0).Select

Wend

End Sub

-----Original Message-----
Is there a way to count only cells that have a specific

background color
AND have a value greater than 0?

I'm very new to VBA but got help from www.cpearson.com on

how to
count/sum cells with background color. It works great

only now I want
to only count the cell if the value is greater than $0.

Any help is greatly appreciated! Thanks.


---
Message posted from http://www.ExcelForum.com/

.