View Full Version : Counting colour cells and containing specified text


BeataG
03-30-2009, 10:04 PM
Hello,

Does anybody know how to write a macro (or function, whatever) that will be accurate for counting the number of cells of specified colour (let's say red ones) and containing specified text e.g. "BM".

Cells in my sheet are white or red, while there is three various texts: "BM", "WA" and "WB".

The range is B2:B58

I would like to get three results:
1) number of red cells and with "BM"
2) number of red cells and with "WA"
3) number of red cells and with "WB"

Thank you in advance for you help,
Regards.

chergh
03-30-2009, 10:47 PM
Take a look at http://www.cpearson.com/excel/colors.aspx

BeataG
03-30-2009, 11:20 PM
Thanks for this site I've just looked through( it is quite interesting), but I couldn't find anything that I can use. Maybe I overlooked something...?

Brianwarnock
03-31-2009, 07:52 AM
The site tells you how to handle colours , it will not give the code for your problem.
You want a development of something like

Private Sub CommandButton1_Click()
Dim counta As Integer
For Each c In Range("B2:B58")

If c.Interior.Color = 255 And c.Value = "xyz" Then counta = counta + 1

Next c

End Sub

This assumes that your RED is 255

Brian

BeataG
03-31-2009, 09:18 AM
Thank you for help. I really appreciate it,
Regards.