Sum if not blank

RincewindWIZZ

Board Regular
Joined
Feb 22, 2005
Messages
81
So I have the following data:
A1:A10 all contain 1 (for simplicity)
B1 to B10 contains formula that evaluate either to a number or to ""
Lets say 8 evaluate to a number (some of which are 0) and 2 evaluate to ""


I want to sum all the cells in A for which the corresponding cell in B is not "" so I tried
SUMIF(A1:A10,criterion,B1:B10)

Criterion Result
"". . . . . . . . gives . . . 2
"<>" . . . . . .gives. . . 10
"<>"&"". . . .gives. . . 10
">""". . . . . .gives. . . .0
">=""". . . . gives. . . .0
">"&"". . . . gives. . . . 0
"<>"&C1. . .gives. . . 10 (c1 contains ="")
So what criterion should I use?

(OK there are other ways I can do this but it seems odd to me that I cannot find an appropriate criterion for SUMIF)
 
Humour me please and try that formula in the spreadsheet linked to above. :-)
When I put =SUMIF(C4:C9,"<>",B4:B9) into D3 I get 9!! but it should be 6

If I delete the contents of C5 and C6 I get the required value 6 but that does not help.
C5 and C6 have formulae that evaluate to "" which is clearly not hte same thing!
 
Last edited:
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I don't trust that site, as I have had bad experiences of them trying downloading rubbish before.
But if it's the same layout as I used in post#10, I suspect that the blank cells aren't blank.

If you put this in d5
=ISBLANK(C5)
what does it say?
 
Upvote 0
No, they are not blank.


If I may quote from my original post . . . .
B1 to B10 contains formula that evaluate either to a number or to ""
 
Upvote 0
OK so it seems I have to do it this way

url]


So the question is what criterion do I put into the SUMIF formula in D4 to give the answer 6 which is the sum of the entries in Col B for which Col C is not blank

=SUMIFS(B:B,C:C,"<>")

should do.But if column B contains formulas, control+shift+enter, not just enter:

=SUM(IF(1-($C$2:$C$100=""),IF(ISNUMBER(1/$B$2:$B$100),$B$2:$B$100+0)))
 
Upvote 0
No, they are not blank.


If I may quote from my original post . . . .
B1 to B10 contains formula that evaluate either to a number or to ""
Can you please post the formula in column B like I asked originally?
If we see exactly what it is doing, I think it will probably become evident to us what is going on.
Many people mistakenly think that a single space is the same as a blank ("" is NOT the same as " ").
 
Upvote 0
=SUMIFS(B:B,C:C,"<>")

should do

Sadly not. Just gives 9 again.

If it is not possible to provide a criterion for the SUMIF, probably easiest is to sum the lot and subtract the ones that are blank because, bizarrely, =SUMIF(C4:C11,"",B4:B11) produces 3, the correct sum of the cells evaluating to blank!

I can find no way acceptable to Excel of having a criterion that is NOT ""
 
Last edited:
Upvote 0
How about
=SUM(SUMIF(C4:C9,{">=0","<0"},B4:B9))
 
Upvote 0
That works.

But how? What is the significance of { } - since its not an array formula

And would it be quicker or slower than the sum - sumif approach?

But then =SUMIF(C4:C9,">=0",B4:B9) seems also to work and is simpler (and robust since values in C can only be numeric or "")
 
Last edited:
Upvote 0
As long as you cannot have negative values in col C, I'd use your formula.
The formula from post#17 if effectively doing 2 sumifs which are then added together by the SUM function.
It's doing a SUMIF if col C ">=0" OR "<0"
 
Upvote 0
The formula from post#17 if effectively doing 2 sumifs which are then added together by the SUM function

Interesting. Had not encountered that construction before. Thank you
Only one condition, no need for external SUM
More than one condition, external Sum

And if you don't do an external sum you presumably get an array with one value per condition?
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top