Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在执行期间调整 for 循环的大小?这是一个简化的例子。
Sub ResizeLoop() last = 5 For i = 0 To last Debug.Print i last = 3 Next End Sub
在第一次通过时i=0,我尝试last通过将其设置为 3 来调整大小,但它仍然一直执行到“5”。
i=0
last
即时窗口:
0 1 2 3 4 5
如果我在执行期间无法重新定义循环,还有另一种方法。
因为“to”在循环开始时被评估一次。使用whileordo while代替:
while
do while
i = 0 last = 5 do while i <= last Debug.Print i last = 3 i = i + 1 loop