For Count = 0 To UBound(totalFraudCells) - LBound(totalFraudCells) + 1
您假设下限是0
.
Dim totalFraud As Range
...
totalFraudCells = totalFraud.Value
But totalFraudCells
是一个基于 1 的二维变体数组。
这些同样如此:
val1 = leftTheBankCells(3)
val2 = stoppedCells(3)
If you know或者希望处理一维数组,您可以使用Application.WorksheetFunction.Transpose
让他们这样:
totalFraudCells = Application.WorksheetFunction.Transpose(totalFraud.Value)
leftTheBankCells = Application.WorksheetFunction.Transpose(leftTheBank.Value)
stoppedCells = Application.WorksheetFunction.Transpose(stopped.Value)
现在您正在查看一维数组,但它们仍然是基于一的。
根据经验,不要假设数组的基数是什么。使用LBound
计算你的下限For
loop:
For Count = LBound(totalFraudCells) To UBound(totalFraudCells)
有了这个每一个值Count
将在范围内totalFraudCells
array.
如果你是not处理单列范围,那么你must处理变体数组的二维性质;LBound
and UBound
可以采用第二个参数作为您想要的下限或上限的维度:
For Count = LBound(totalFraudCells, 1) To UBound(totalFraudCells, 1)
如果您需要迭代所有行和列,你需要嵌套循环,内循环迭代LBound(totalFraudCells, 2) To UBound(totalFraudCells, 2)
对于第一维中的每个下标。