Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Counting/summing cells based on background color

Is there a way to count only cells that have a specific background colo
AND have a value greater than 0?

I'm very new to VBA but got help from www.cpearson.com on how t
count/sum cells with background color. It works great only now I wan
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

  #2   Report Post  
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/

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Counting/summing cells based on background color

This doesn't seem to work. It might be because I just don't understan
well enough. My data is not contiguous which may also be my problem

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help in counting and summing cells based on multiple conditions Dave Excel Worksheet Functions 9 November 13th 09 04:23 PM
Find cells w/background color based on conditional formatting Freida Excel Worksheet Functions 2 November 17th 08 08:36 PM
Summing cells within a column based on cell fill color Jim D. New Users to Excel 2 October 8th 08 04:56 PM
Change font and background color of several cells based on result of a formula Zenaida Excel Discussion (Misc queries) 2 April 27th 06 06:46 PM
counting cells in a column based on thier color Niek Otten Excel Programming 0 January 20th 04 09:11 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"