具有各种条件的VBA循环

时间:2019-04-11 16:31:13

标签: vba loops

我的循环结构如下:

For n = 1 to 10
   If [condition 1] Then
      For i = 1 to 10
         If [condition 2] Then
            [action]
            [EXIT THE INNER LOOP AND START OUTER LOOP with n = 2]
         Elseif [condition 3] Then
            [action 2]
            [EXIT FUNCTION]
         Elseif [condition 4] Then
            [action 3]
            [EXIT BOTH LOOPS]         
         End If
      Next i
   End If
Next n

鉴于各种操作,我应该如何正确编码?

我尝试过:

For n = 1 to 10: Do
   If [condition 1] Then
      For i = 1 to 10
         If [condition 2] Then
            [action]
            GoTo NextIteration
         Elseif [condition 3] Then
            [action 2]
            Exit Function
         Elseif [condition 4] Then
            [action 3]
            Exit Do      
         End If
      Next i
   End If
NextIteration: Next n
Do while negative: Next n

我不确定如何正确地写最后两行。

任何帮助将不胜感激。

0 个答案:

没有答案