vba 计算范围内填充单元格的数量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14245507/
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 number of populated cells in range
提问by Sam
How do I count the number of populated cells (with text/number or combinations of text+number)?
如何计算填充单元格的数量(带有文本/数字或文本+数字的组合)?
I tried =countif(A2:A2000,1=1)
(with a general criteria, e.g. 1=1 always) but shows zero (0) for a text column.
我尝试过=countif(A2:A2000,1=1)
(使用一般标准,例如始终为 1=1)但对于文本列显示零 (0)。
回答by Varun Rajan
I think for the answer above, it should rather be
我认为对于上面的答案,它应该是
Application.WorksheetFunction.CountA(Range("A2:A2000"))
I have always faced problems while not mentioning Range, cause it considers the whole range to be as a single unit.
我总是遇到问题而没有提到 Range,因为它认为整个范围是一个单一的单位。
回答by KurtisT
In VBA it's WorksheetFunction.CountA("A2:A2000")
在 VBA 中它是 WorksheetFunction.CountA("A2:A2000")
回答by Jüri Ruut
The formula is =COUNTA(A2:A2000)
: non-blank cells are counted.
公式为=COUNTA(A2:A2000)
:计算非空白单元格。
回答by user2965711
Dim Coloumncount As Integer Coloumncount = Application.WorksheetFunction.CountA([D1:D100])'count how many filled cell in coloumn "D"
Dim Coloumncount As Integer Coloumncount = Application.WorksheetFunction.CountA([D1:D100])'计算列“D”中有多少个填充单元格