For j = 1 To 8
Sheet5.Cells(j + 1, 2) = 480
Next
t = 0
c = 0
For j = LBound(arrayTime) + 1 To UBound(arrayTime)
MsgBox "j " & j
'MsgBox (t)
numMins = Sheet5.Cells((j + 1) - (8 * c), 2) - arrayTime(j)
If numMins < 0 Then
t = t + 1
ReDim Preserve arrayTime(numrows - 1 + t)
arrayTime(numrows - 1 + t) = arrayTime(j)
MsgBox (arrayTime(numrows - 1 + t))
Else
Sheet5.Cells((j + 1) - (8 * c), 2) = numMins
End If
If j = 8 * (c + 1) Then
c = c + 1
End If
MsgBox ("end " & t)
Next
我试图在条件为真的情况下向arrayTime添加一个值。我成功添加了它,但是for循环不会重新定义尺寸以遍历添加的元素。该数组最初包含12个元素,然后我添加了第13个元素,但是该循环确实可以识别第13个元素,并且仅循环了12次。关于如何使for循环循环13次的任何建议?
添加一个循环计数器,例如i
,并将其设置为LBound(arrayTime) + 1
然后使用Do Until (i = UBound(arrayTime))
。这迫使VBA在每个循环之前重新计算上限。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句