vba 对列进行计数/求和但排除 #N/A
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42428105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Count/Sum a column but exclude #N/A
提问by LOZ
Currently using the following forumlas to count the number of records in all of column Z that does not have #N/A but it does not work. All the rows in Column Z have a formula itself (Which is why some of them display #N/A, its a VLOOKUP).
目前使用以下论坛来计算所有 Z 列中没有 #N/A 但它不起作用的记录数。Z列中的所有行本身都有一个公式(这就是为什么其中一些显示#N/A,它是一个VLOOKUP)。
=COUNTA(Z:Z)-SUM(IF(ISNA(Z:Z),1))
=SUMPRODUCT(--(TRIM(Z:Z)<>"#N/A"))
These return a "0" value which is not true, what am I doing incorrect?
这些返回一个不正确的“0”值,我在做什么不正确?
回答by chris neilsen
If you are using Excel 2010 or later, to count non-error values you can use (regular formula)
如果您使用的是 Excel 2010 或更高版本,要计算可以使用的非错误值(常规公式)
=AGGREGATE(3,6,Z:Z)
回答by Wedge
No reason to use an array formula for this, you can just do something like
没有理由为此使用数组公式,您可以执行以下操作
=COUNTIFS(Z:Z, "<>#N/A",Z:Z, "<>")
or
或者
=COUNTA(Z:Z) - COUNTIF(Z:Z,"=#N/A")
The first one counts every nonblank, non #N/A cell. The second does what you're trying to do now and subtracts the total of #N/A cells from the total of every nonblank cell. Maybe using ISNA is technically more correct or faster, but this probably works just as well for most cases.
第一个计数每个非空白、非#N/A 单元格。第二个执行您现在要做的事情,并从每个非空白单元格的总数中减去 #N/A 单元格的总数。也许使用 ISNA 在技术上更正确或更快,但这可能适用于大多数情况。
回答by A.S.H
This array formulasums the cells of range Z:Zthat are not NA's :
此数组公式对Z:Z不属于 NA 的范围单元格求和:
=SUM(IF(NOT(ISNA(Z:Z)),Z:Z)) Ctrl+Shift+Enter
This one (which is probably what you want) sums all but errors:
这个(可能是您想要的)总结了除错误之外的所有内容:
=SUM(IF(NOT(ISERROR(Z:Z)),Z:Z)) Ctrl+Shift+Enter
And another (simpler) one
另一个(更简单的)
=SUM(IFERROR(H:H, 0)) Ctrl+Shift+Enter
回答by Andrew
Are you entering it as an array formula? Press Ctrl-Shift-Enter instead of just enter. I think the first formula should work.
您是否将其作为数组公式输入?按 Ctrl-Shift-Enter 而不是直接输入。我认为第一个公式应该有效。
=COUNTA(Z:Z)-SUM(IF(ISNA(Z:Z),1))


