Count Interior Colour

S

Steve

Hi, where certain cells contain certain data I choose these cells and
fill them with the colour green.

I would like to create a macro/module that counts the number of cells
with the fill colour as green.

Thanks in advance

Steve
 
S

Steve

Hi Claus, I have looked at the link provided and also used the ASAP
Utilitites macro to do exactly what I want. However, when I tried to
use ASAP utilities again today I kept getting out of resources errors

I do have a module that counts the number of cells with a yellow
background as follows:

Function CountYellow(rg As Range) As Long
Dim c As Range
Dim t As Long
For Each c In rg
If c.Interior.Color = vbYellow Then t = t + 1
Next c
CountYellow = t
End Function


However, when I change vbYellow to vbGreen it deosnt work and whenm I
have changed yellow to 43 (the interior coour) it still doesnt work.

Any advice or help appreciated

Thanks


Steve
 
C

Claus Busch

Hi Steve,

Am Wed, 19 Dec 2012 16:55:08 +0000 schrieb Steve:
Function CountYellow(rg As Range) As Long
Dim c As Range
Dim t As Long
For Each c In rg
If c.Interior.Color = vbYellow Then t = t + 1
Next c
CountYellow = t
End Function

However, when I change vbYellow to vbGreen it deosnt work and whenm I
have changed yellow to 43 (the interior coour) it still doesnt work.

it is possible that your colorindex is diffrent. Select a colored cell
and write in Direct window of VB Editor:
?Activecell.Interior.ColorIndex
So you'll get your exact colorindex. Then change your code to:
If c.Interior.ColorIndex = "Your ColorIndex" Then t = t + 1



Regards
Claus Busch
 

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