Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如果语句得到满足,则在2个嵌套循环中中断内部循环_Vba_Excel_Loops_For Loop - Fatal编程技术网

Vba 如果语句得到满足,则在2个嵌套循环中中断内部循环

Vba 如果语句得到满足,则在2个嵌套循环中中断内部循环,vba,excel,loops,for-loop,Vba,Excel,Loops,For Loop,我已经编写了以下代码,我想中断m的循环,但如果(if)语句返回true,我想继续I的循环 For i = 7 To lastrow For m = 33 To 37 If IsNumeric(mmk.Sheets("FG").Cells(i, m)) = True Then quote(i, m) = mmk.Sheets("FG").Cells(i, m) End If If quote(i, m) <&

我已经编写了以下代码,我想中断m的循环,但如果(if)语句返回true,我想继续I的循环

For i = 7 To lastrow
    For m = 33 To 37

        If IsNumeric(mmk.Sheets("FG").Cells(i, m)) = True Then
            quote(i, m) = mmk.Sheets("FG").Cells(i, m)
        End If

        If quote(i, m) <> Empty And quote(i, m) <> 0 And quote(i, m) > 0 Then
            row(i, m) = i
        End If

       row1(i) = row(i, m)

       If row1(i) <> Empty And row1(i) <> 0 And row1(i) > 0 Then
           mmk.Sheets("FG").Rows(row1(i)).Select
           Selection.Copy
           wrk.Activate
           wrk.Sheets("Nego").Activate

           With ActiveSheet
               last1 = .Cells(.Rows.Count, "A").End(xlUp).row
           End With

           wrk.Sheets("Nego").Cells(last1 + 1, 1).Select
           ActiveSheet.Paste
           Exit For
           Next i
        Else
           Next m
           Next i
        End If

这是一个在正确的地方检查你的退出条件是否正确的问题。 退出内环应该发生在内环内

Sub BreakInnerLoops()

Dim i As Integer
Dim j As Integer
Dim k As Integer

For i = 1 To 10
    For j = 1 To 10
        For k = 1 To 10
            Debug.Print i & " " & j & " " & k
            If k = 5 Then Exit For 'Exits k loop.
        Next k
        If j = 5 Then Exit For 'Exits j loop.
    Next j
    If i = 5 Then Exit For 'Exits i loop.
Next i

End Sub
就你而言:

For i = 7 To lastrow 
    For m = 33 To 37
        'Some lines here.
        If row1(i) <> Empty And row1(i) <> 0 And row1(i) > 0 Then 'Exit condition and do stuff.
            mmk.Sheets("FG").Rows(row1(i)).Select
            Selection.Copy
            wrk.Activate
            wrk.Sheets("Nego").Activate
            With ActiveSheet
                last1 = .Cells(.Rows.Count, "A").End(xlUp).row
            End With
            wrk.Sheets("Nego").Cells(last1 + 1, 1).Select
            ActiveSheet.Paste
            Exit For
        End If
    Next m
Next i
i=7至最后一行的

对于m=33到37
“这里有几行。
如果行1(i)为空且行1(i)0和行1(i)>0,则“退出条件并执行操作”。
mmk.图纸(“FG”).行(第1(i)行)。选择
选择,复制
工作。激活
工作表(“Nego”)。激活
使用ActiveSheet
last1=.Cells(.Rows.Count,“A”).End(xlUp).row
以
工作表(“Nego”)单元格(last1+1,1)。选择
活动表。粘贴
退出
如果结束
下一个m
接下来我

此外,您可能需要阅读

如果退出条件为真,则需要在正确的位置进行检查。 退出内环应该发生在内环内

Sub BreakInnerLoops()

Dim i As Integer
Dim j As Integer
Dim k As Integer

For i = 1 To 10
    For j = 1 To 10
        For k = 1 To 10
            Debug.Print i & " " & j & " " & k
            If k = 5 Then Exit For 'Exits k loop.
        Next k
        If j = 5 Then Exit For 'Exits j loop.
    Next j
    If i = 5 Then Exit For 'Exits i loop.
Next i

End Sub
就你而言:

For i = 7 To lastrow 
    For m = 33 To 37
        'Some lines here.
        If row1(i) <> Empty And row1(i) <> 0 And row1(i) > 0 Then 'Exit condition and do stuff.
            mmk.Sheets("FG").Rows(row1(i)).Select
            Selection.Copy
            wrk.Activate
            wrk.Sheets("Nego").Activate
            With ActiveSheet
                last1 = .Cells(.Rows.Count, "A").End(xlUp).row
            End With
            wrk.Sheets("Nego").Cells(last1 + 1, 1).Select
            ActiveSheet.Paste
            Exit For
        End If
    Next m
Next i
i=7至最后一行的

对于m=33到37
“这里有几行。
如果行1(i)为空且行1(i)0和行1(i)>0,则“退出条件并执行操作”。
mmk.图纸(“FG”).行(第1(i)行)。选择
选择,复制
工作。激活
工作表(“Nego”)。激活
使用ActiveSheet
last1=.Cells(.Rows.Count,“A”).End(xlUp).row
以
工作表(“Nego”)单元格(last1+1,1)。选择
活动表。粘贴
退出
如果结束
下一个m
接下来我
你也可能想读一读