如何在嵌套(内部)do-while 中完成 If-Then 后 exit/skip outter do-while

How to exit/skip outter do-while after finishing If-Then in nested(inner) do-while

我是 VBA 处理一些实际工作问题的新手,我在完成内部(嵌套)do-while 后退出 do-while 时遇到问题。

*代码工作正常,没有问题,但我想知道如何通过 exit/skip outter do-while 一旦匹配内部 if-then 并完成 ## 来提高效率.

代码如下(仅供参考,为了便于阅读,我删除了一些代码):

 For Each w In Worksheets  
    If () Then

       Do While (i)  ' outter do-while

            Do While ()   'inner(nested/1st do-while)
                    If () Then  'match something here

                        ## do something here

                        Exit Do      'break the inner do-while
                    End If

            Loop

            i = i + 20   'question here!!how should I break outter do-while?

        Loop                       
     End If
  Next w

所以,我的目标是,一旦 if-then 匹配并且 ##content 完成,我怎么能直接转到 "next w",也就是跳转到下一个工作表?

我试了"goto+line"但是不行,还有别的办法吗?

你可以试试这样:

Dim exitLoop As Boolean '<--| default initial value is 'False'

For Each w In Worksheets
    If () Then

        Do While (i) And Not exitLoop  ' outer do-while

            Do While () and Not exitLoop 'inner(nested/1st do-while)
                    If () Then  'match something here

                        ## do something here

                        exitLoop = True
                        Exit Do      'break the inner do-while
                    End If

            Loop

            i = i + 20   'question here!!how should I break outter do-while?

        Loop
        exitLoop = False '<--| set back default value
     End If
 Next w