Excel Sum if not Null String

自闭症网瘾萝莉.ら 提交于 2019-12-23 02:33:11

问题


I would like to sum all cells in column B that corresponds to cells in column A which are not empty. However, in Excel, the term "not empty" is a bit ambigious: if a cell contains a formula, but the result is a null string, i.e. =IF(1=0,1,"") , it is considered not empty, even though the result is essentially nothing.

However, I want to exclude such cells.

The obvious thing to try first is

=SUMIF(A:A,"<>",B:B)

But this does not work, because the operator <> only says a cell is empty if it is exactly that: empty. If there's a formula in it, such as =IF(1=0,1,""), it is considered "not empty", as explained above.

In my Google adventures I've also learned that "=" is the converse of "<>" in the formula above, but this does not help me, as far as I can tell.

What makes my problem even more challengeing is that I want to include cells in column B which correspond to both text and numeric entries in column A...

I can think of various ways to "work around", but I'm actually after a solution where I don't have to add another column to my data and where I can leave my data as is.

Thanks!


回答1:


The behaviour of COUNTIF(S)/SUMIF(S) I agree is a touch frustrating with respect to null strings.

You can try:

=SUM(SUMIF(A:A,{"?*",">=0"},B:B))

if the numbers in column A are strictly non-negative, or, if not:

=SUM(SUMIF(A:A,{"?*",">=0","<0"},B:B))

Alternatively you can switch to SUMPRODUCT, which does not suffer from such ambiguous handling of null strings:

=SUMPRODUCT(0+(A1:A15<>""),B1:B15)

though which has the drawback that, unlike with COUNTIF(S)/SUMIF(S), you cannot arbitrarily reference as many cells as you wish without detriment to performance (hence my choice of an upper row reference of 15): in fact, the use of entire column references within SUMPRODUCT is a disastrous idea.

Regards




回答2:


I was trying to do something similar with a CUBEVALUE formula which can return "" instead of 0.

To get SUM and addition (+) to work I used =VALUE("0" & CUBEVALUE(uglyforumlahere)) rather than using IF statements to check if the CUBEVALUE(uglyforumlahere)) evaluates to "" then having to repeat the CUBEVALUE(uglyforumlahere)) if it doesn't.

I also threw an IFNA() in there as well, so the end result is =VALUE("0" & IFNA(CUBEVALUE(uglyforumlahere),0))



来源:https://stackoverflow.com/questions/35085386/excel-sum-if-not-null-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!