Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA中计数函数的替代方法_Excel_Vba - Fatal编程技术网

Excel VBA中计数函数的替代方法

Excel VBA中计数函数的替代方法,excel,vba,Excel,Vba,我正在尝试为在VBA脚本中使用的count函数寻找替代方法 我试图计算数组中的单元格数,然后使用该值定义for循环 我试过以下方法 NoColdReadings = ActiveCell.FormulaR1C1 = "=COUNT('5. Summary Information'!R[-7]C[5]:R[90]C[5])" NumberOfColdProbes = ActiveSheet.Range("L4").End(xlDown).Row MsgBox NumberOfColdProbes

我正在尝试为在VBA脚本中使用的count函数寻找替代方法


我试图计算数组中的单元格数,然后使用该值定义for循环

我试过以下方法

NoColdReadings = ActiveCell.FormulaR1C1 = "=COUNT('5. Summary Information'!R[-7]C[5]:R[90]C[5])"
NumberOfColdProbes = ActiveSheet.Range("L4").End(xlDown).Row

MsgBox NumberOfColdProbes


For i = 4 To (Sheets("4. Word Doc").Range("H36").Value + 4)

ColdProbe = Cells(i, 12).Value
ListofCold = ListofCold & ColdProbe & Sepr

Next
NoColdReads返回False,NumberOfColdProbes返回101,这是数组的总大小

有没有其他方法可以计算VBA中数组中的单元格数

PS.我试图计数的数组中的数据具有以下格式:

=IFERROR(IF(M4<>"",INDEX($D$4:$D$102,MATCH(IFERROR(SMALL($E$4:$E$102,C4),""),$E$4:$E$102,0)),""),"")
=IFERROR(如果(M4)”,索引($D$4:$D$102,匹配(IFERROR(小($E$4:$E$102,C4),“”),$E$4:$E$102,0)),“”),“”)

并返回“130854”等。

RHS-
ActiveCell.FormulaR1C1=“=COUNT('5.摘要信息'!R[-7]C[5]:R[90]C[5])”
的计算结果为TRUE/FALSE。不能像这样链接赋值:
foo=bar=someExpression
,它的计算结果为
foo=(bar=someExpression)
,即
foo={boolean}
,这是您的
False
值。至于行#是数组中的最后一个单元格,这是因为您使用的是
.End(xlDown)
-从工作表底部开始,使用
.End(xlUp)
。“计算数组中的单元格数”,数组不包含单元格。如果使用数组元素的数量来“定义for循环”,则使用
for i=LBound(arr)到UBound(arr)
将定义循环。如果试图计算数组中作为值的元素数,则必须循环数组,测试每个非空元素,并使用计数器添加它们。或者只计算用于定义范围数组的范围中的常量数。