gpt4 book ai didi

excel - 跳出 While...Wend 循环

转载 作者:行者123 更新时间:2023-12-01 16:16:43 28 4
gpt4 key购买 nike

我正在使用 VBA 的 While...Wend 循环。

Dim count as Integer

While True
count=count+1

If count = 10 Then
''What should be the statement to break the While...Wend loop?
''Break or Exit While not working
EndIf
Wend

我不想使用“While count<=10...Wend”之类的条件

最佳答案

While/Wend 循环只能通过 GOTO 或从外部 block 退出(Exit sub /function 或另一个可退出循环)

改为 Do 循环:

Do While True
count = count + 1

If count = 10 Then
Exit Do
End If
Loop

或者循环一定次数:

for count = 1 to 10
msgbox count
next

(上面可以使用Exit For提前退出)

关于excel - 跳出 While...Wend 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12200834/

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