count blank cells

A

Annette

I'm thinking this might be easy, but maybe I'm wrong! I want to count the
number of blank cells found in column E ... I have will information in
column D with no blank spaces starting with row 2. Is there a formula that
would count this?
 
P

Peo Sjoblom

Because it doesn't work, at least it is not reliable. Without putting
anything in any of the cells
A1:A20 try

=COUNTIF(A1:A20,"")

The correct way to do this would be to use either

=COUNTBLANK(A1:A20)

or

=SUMPRODUCT(--(A1:A20=""))
 
D

Dave R.

Can you give an example when SUMPRODUCT(--(A1:A20="")) is more reliable than
COUNTIF(A1:A20,"") ?

They both return 20 for me using your instructions. Adding "" to some cells
returns 20 for both also.
 
P

Peo Sjoblom

Really!? Frankly you cannot use countif for this, what if you want to count
let's say
A2:A1000, assuming you will fill down from top, just as an example take a
new sheet,
put text in A2:A20. Now use

=COUNTBLANK(A2:A1000)

and

=SUMPRODUCT(--(A2:A1000=""))

then use

=COUNTIF(A2:A1000,"")

Note that you should leave A21:A1000 alone, don't put anything there


as you can see unless you use A1000 and put something there and then delete
it countif
will be terribly wrong. It is a fairly known bug that has to do with the
used range and that's why
COUNTIF shouldn't be used in this fashion.
It will only work if you have used the cells in question, not if they
were empty from the start
 
D

Dave R.

Um, are we using different versions, or is something being lost in
translation?

I tried your experiment and got 980 for each method. Adding text to any
other cell changed it to 979 for all, deleting it gave 980 again for all.

I use XL 2003 here in case that is a factor, or your experiment instructions
aren't quite clear enough (tho they seem quite clear from here).
 
F

Frank Kabel

Hi
in addition to Peo there have been several discussion about this topic.
Just try this formulas on a new blank, fresh workbook :)
 
D

Dave R.

Frank,

Are you suggesting I'm using a dirty, old workbook to try these? :)

I did it once more from scratch, though I have to admit it's getting a bit
boring especially when no one has stated WHAT would go horribly wrong, and
at what point. I don't see any difference between those formulas in counting
blank cells in A2:A1000.. no matter what I put in them or delete from them
they all give the same number.

If the next step is to reboot my computer in safe mode, open only Excel and
try it, well I'd have to end my curiosity here.
 
F

Frank Kabel

Hi
if you have Excel 2003 you won't see the error. It was silently fixed.
Before this version this formula just counts wrong.
 
P

Peo Sjoblom

As I stated it seems to have been fixed in 2003, but since a majority of
users don't use 2003 I am sure
that using countif should not be the norm, especially since there is a
function especially for
counting blanks
 
H

Harlan Grove

As I stated it seems to have been fixed in 2003, but since a majority of
users don't use 2003 I am sure that using countif should not be the norm,
especially since there is a function especially for counting blanks
...

In XL97 at least, COUNTBLANK counts truly blank cells and cells evaluating to
"". Depends on one's definition of 'blank'.

FTHOI, since I like almost pointless compilations of arcane information, start
with a new worksheet. Select A1:A20 and enter foo in all cells (type foo and
press [Ctrl]+[Enter]), then clear A1:A20. Enter the following formulas.

B1: =COUNTBLANK($A$1:$A$20)
B2: =SUMPRODUCT(--($A$1:$A$20=""))
B3: =COUNTIF($A$1:$A$20,"")
B4: =COUNTIF($A$1:$A$20,"=")
B5: =COUNTIF($A$1:$A$20,"<>?*")
B6: =SUMPRODUCT(--ISBLANK($A$1:$A$20))
B7: =ROWS($A$1:$A$20)*COLUMNS($A$1:$A$20)-COUNTA($A$1:$A$20)

All should start out evaluating to 20. Now enter the formula ="" in cell A1.
These formulas should now evaluate to

B1: 20
B2: 20
B3: 20
B4: 19
B5: 20
B6: 19
B7: 19

So, if one wants to count truly blank cells, NOTHING beats

=SUMPRODUCT(--ISBLANK(Range))

in any Excel version in terms of clarity of intent since COUNTBLANK's purpose is
muddied by the fact that it includes cells evaluating to "", but FWIW

=COUNTIF(Range,"=")

seems to produce the same results (at least from my own light testing).
 
L

lindasf

I use EXCEL 2000 and have to run calculations on spreadsheets given t
me by users. Sometimes the users put in blanks (using delete or clear
and sometimes they hit the space bar. When I use the SUMPRODUC
provided to me by Frank, only the spaces are counted. This means that
have to manually go in and enter spaces in those fields. Of course
can use filldown, but the cells are often not contiguous. Can anyon
please tell me how to get around this? Thx. much.

PLEASE SEE VERY BOTTOM OF THIS POST. THANKS.

lindasf

Posted by lindasf on 04-27-2004 07:26 PM:
Conditional IF statements and totals

Logically, I would like to do the following:

(Both D2 and C2 refer to job codes).

If D2 = space, add 1 to the counter for value in C2

If D2 not equal space, add 1 to the counter for value in D2.

The end result would be that I have different totals for the variou
job codes.

I have tried using SUMPRODUCT and IF statements, but without any luck.

Attached is the file in question.

Thank you.

lindasf


--------------------------------------------------------------------------------
Posted by Frank Kabel on 04-27-2004 07:42 PM:
Re: Conditional IF statements and totals

Hi
even after looking at your file still not clear what you're trying to
achieve. Please post some example rows in plain text (no attachment)
and describe your expected result based on this example data

--
Regards
Frank Kabel
Frankfurt, Germany

Logically, I would like to do the following:

(Both D2 and C2 refer to job codes).

If D2 = space, add 1 to the counter for value in C2

If D2 not equal space, add 1 to the counter for value in D2.

The end result would be that I have different totals for the various
job codes.

I have tried using SUMPRODUCT and IF statements, but without any luck.

Attached is the file in question.

Thank you.

lindasf

Attachment filename: position control pc03-04_041204 - inv
only-forum.xls Download attachment:
http://www.excelforum.com/attachment.php?postid=526366 ---
Message posted




--------------------------------------------------------------------------------
Posted by lindasf on 04-27-2004 08:19 PM:
Conditional IF statements and totals

I am trying to create a counter for each job code. Since there are 6
rows in the file, the total of all the job code counters should equa
68.

Each row in the file refers to an employee (I have deleted their name
for obvious reasons). If an employee has a value in both the C and
columns, it means he has been promoted and the value in the D colum
should be used (and added to the counter for that value) instead of th
value in the C column.

A B C D
Row 2 INV 14260001 1426
Row 3 INV 14260002 1426
Row 9 INV 14260008 1426 1632
Row 14 INV 16320000.5 1632


In row 2, since D2 is blank, use the job code in C2 and add 1 to th
counter for the 1426 job codes.

In row 3, since D2 is blank, use the job code in C2 and add 1 to th
counter for the 1426 job codes.

In row 9, since D2 is NOT blank, use the job code in D2 and add 1 t
the counter for the 1632 job codes.

In row 14, since D2 is blank, use the job code in C2 and add 1 to th
counter for the 1632 job codes.

Expected result (for this 4 row file) would be:

1426 = 2
1632 = 2

P.S. I hope the columns align (they seem to have a mind of their own
to illustrate what I was saying. If not please refer to the attache
EXCEL and you will see the rows in question. Thx.


--------------------------------------------------------------------------------
Posted by Frank Kabel on 04-27-2004 09:10 PM:
Re: Conditional IF statements and totals

Hi
try
=SUMPRODUCT(--(C2:C100=1426),--(D2:D100=""))

and
=SUMPRODUCT(--(D2:D100=1632))


--
Regards
Frank Kabel
Frankfurt, Germany

I am trying to create a counter for each job code. Since there ar 68
rows in the file, the total of all the job code counters shoul equal
68.

Each row in the file refers to an employee (I have deleted their names
for obvious reasons). If an employee has a value in both the C and D
columns, it means he has been promoted and the value in the D column
should be used (and added to the counter for that value) instead of
the value in the C column.

A B C D
Row 2 INV 14260001 1426
Row 3 INV 14260002 1426
Row 9 INV 14260008 1426 1632
Row 14 INV 16320000.5 1632


In row 2, since D2 is blank, use the job code in C2 and add 1 to the
counter for the 1426 job codes.

In row 3, since D2 is blank, use the job code in C2 and add 1 to the
counter for the 1426 job codes.

In row 9, since D2 is NOT blank, use the job code in D2 and add 1 to
the counter for the 1632 job codes.

In row 14, since D2 is blank, use the job code in C2 and add 1 to the
counter for the 1632 job codes.

Expected result (for this 4 row file) would be:

1426 = 2
1632 = 2

P.S. I hope the columns align (they seem to have a mind of their own)
to illustrate what I was saying. If not please refer to the attached
EXCEL and you will see the rows in question. Thx.

Attachment filename: position control pc03-04_041204 - inv
only-forum.xls Download attachment:
http://www.excelforum.com/attachment.php?postid=526482 ---
Message posted




--------------------------------------------------------------------------------
Posted by lindasf on 04-27-2004 09:50 PM:
conditional IF statements and totals

Thank you Frank.

Your SUMPRODUCT statements work, but I was hoping there would be a more
automatic way to do this.

There are many job codes involved and I would have to manually create
many formulas to catch them all.

On another note, I did say "test for space" but I guess what I really
meant is "test for space OR blank (e.g. null)".

Many of the "blank" cells in Column D are not counted (but I want them
to be counted) because they contain a null value. I could, of course,
go in and change all the null values to spaces, but this would be quite
a bit of work.

Is there a way to test for space OR blank?

Thx much.

lindasf
 
P

Peo Sjoblom

Harlan Grove said:
As I stated it seems to have been fixed in 2003, but since a majority of
users don't use 2003 I am sure that using countif should not be the norm,
especially since there is a function especially for counting blanks
..

In XL97 at least, COUNTBLANK counts truly blank cells and cells evaluating to
"". Depends on one's definition of 'blank'.

FTHOI, since I like almost pointless compilations of arcane information, start
with a new worksheet. Select A1:A20 and enter foo in all cells (type foo and
press [Ctrl]+[Enter]), then clear A1:A20. Enter the following formulas.

B1: =COUNTBLANK($A$1:$A$20)
B2: =SUMPRODUCT(--($A$1:$A$20=""))
B3: =COUNTIF($A$1:$A$20,"")
B4: =COUNTIF($A$1:$A$20,"=")
B5: =COUNTIF($A$1:$A$20,"<>?*")
B6: =SUMPRODUCT(--ISBLANK($A$1:$A$20))
B7: =ROWS($A$1:$A$20)*COLUMNS($A$1:$A$20)-COUNTA($A$1:$A$20)

All should start out evaluating to 20. Now enter the formula ="" in cell A1.
These formulas should now evaluate to

B1: 20
B2: 20
B3: 20
B4: 19
B5: 20
B6: 19
B7: 19

So, if one wants to count truly blank cells, NOTHING beats

=SUMPRODUCT(--ISBLANK(Range))

in any Excel version in terms of clarity of intent since COUNTBLANK's purpose is
muddied by the fact that it includes cells evaluating to "", but FWIW

=COUNTIF(Range,"=")

seems to produce the same results (at least from my own light testing).


FWIW =COUNTIF(A1:A20,"=") returns the same result on 2003
as well. I agree about ISBLANK, although many people consider
="" to be blank as well and would probably disagree with the result
of using ISBLANK. Heck! I have seen many people here thinking a
space in a cell equals blank
 
P

Peo Sjoblom

I think the excelforum's link to this NG is screwed up!?

Regardless, use data>validation and prevent a user entering a space,
it sounds insane to me using a space as a criteria.
custom validation to prevent entering of a space would be

=CODE(A1)<>32

hopefully nobody would be so stupid that they copy a space and paste it in
the problem would be if somebody cleared everything from the cell, that
would remove
validation.. You just have to teach the users not to do this..
 
H

Harlan Grove

Peo Sjoblom said:
hopefully nobody would be so stupid that they copy a space and paste
it in . . .

Clearly you haven't worked with my users! Grove's first corollary to
Murphy's Law: users will eventually make all invalid entries that aren't
specifically trapped and rejected. Grove's second corrollary: developers
overestimate the mean time between untrapped invalid entries by at least an
order of magnitude.

If users could clear cells, enter apostrophes or spaces, then the safest
check for counting all such 'blanks' is

=SUMPRODUCT(--(TRIM(Range)=""))
 
H

Harlan Grove

Peo Sjoblom said:
. . . Heck! I have seen many people here thinking a
space in a cell equals blank

One can only conclude that the space in such a cell is as blank as the space
between such users ears.
 

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