添加VBA数组

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次。 任何build议如何获得循环13次循环?

添加一个循环计数器,说i ,并将其设置为LBound(arrayTime) + 1然后使用Do Until (i = UBound(arrayTime)) 。 这迫使VBA重新计算每个循环之前的上界。