gpt4 book ai didi

excel - 如何在 Excel VBA 中退出 1 个以上的 for 循环?

转载 作者:行者123 更新时间:2023-12-01 10:21:53 25 4
gpt4 key购买 nike

代码如下:

'first for loop
for I = 1 to 5
do sth
'second for loop
for j = 2 to 7
do sth
'third for loop
for m = 2 to 43
if [condition] then
exit 2nd and 3rd loop and continue on next I ?????
end if
next
next
next

我写了两个 Exit For ,但它没有帮助。它只退出了第三个 for 循环并继续下一个 j。

最佳答案

如果在循环中嵌套一个标志,则可以在循环第二个循环之前放置一个 if 语句。如果标志为真,那么您也退出第二个循环。

'first for loop
for I = 1 to 5
do sth
'second for loop
for j = 2 to 7
do sth
'third for loop
for m = 2 to 43
if [condition] then
flg = True
Exit for
end if
next
If flg = True then Exit For
next
next

关于excel - 如何在 Excel VBA 中退出 1 个以上的 for 循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28905934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com