How to add up all cells with no fill color

G

Guest

Hello,

I copied a function called "CountCol" which will help me count the colored
cells in my spreadsheet. I have to type the following function in my
spreadsheet,
=countcol(a1:a100,6), and it will count--in this case--all the cells in the
range a1:a100 that have color yellow (6 stands for the color index which
equals yellow).

What is the color index for "no fill"?
(I want to count all the cells with text which have no fill)

Thanks for your help!
 
G

Guest

Try using the Excel constant xlNone where you have the color index number in
your function
 
G

Guest

Hello Kevin B,

I did and it returned a #Value! error.
I wrote it like this: countcol(a1:a100,xlNone)

Did I write it incorrectly?

Thanks,
Kris
 
G

Guest

No, I was dead wrong about that one. I'll see if I can find the numeric
value of the xlNone constant.
 
G

Guest

Try the following value, which corresponds to the Excel constant which did
not work:

-4142
 
G

Guest

I tried:

=countcol(a1:a100,-4142)

and I got 22,000 or so for the answer. I think what it is doing is counting
every no fill space rather than just the spaces that have text and no fill.
Is there another color index # for "no fill" b/c I know the code I copied to
create this function works?

Thanks for your help.
 
G

Guest

Yes, that's the value Kevin B though migh work but I think it is just
counting every no fill cell I have in my range rather than the cells that
have no fill *and* text.

I appreciate your help!
 
B

Bernie Deitrick

Perhaps modify your code along these lines:

Function CountCol(r As Range, col As Variant)
Dim c As Range
For Each c In r
If c.Interior.ColorIndex = col And _
Application.IsText(c.Value) Then _
CountCol = CountCol + 1
Next c
End Function


HTH,
Bernie
MS Excel MVP
 
G

Guest

Thank you, Bernie! I think that did the trick! I even did a rough count to
double check and think that did it!!

I appreciate your help very much!!!
 

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

Similar Threads


Top