直到Do循环嵌套在无法在excel VBA中编译的do while循环中

时间:2019-05-08 10:29:36

标签: excel vba do-loops

该代码无法编译,并在Do直到循环中显示错误。它说有一个循环,没有执行。这里有更多代码,可以正常工作,并且模块顶部有Option Explicit。故障标记将2标记为最后一个循环。我想念什么?

我试图将代码放在单独的子目录中 我尝试过


    intLastrowData = wbold.Worksheets(OldSheetName).Cells(Rows.Count, 1).End(xlUp).Row
    intLastrowNew = WBnew.Worksheets(AktivtBlad).Cells(Rows.Count, 1).End(xlUp).Row
    i = 3
    Do While i <= intLastrowNew
        strValueA = WBnew.Cells(i, intData1).Value
        strValueB = WBnew.Cells(i, intData2).Value
        j = 2
        Do Until strValueA = wbold.Worksheets(OldSheetName).Cells(j, 1).Value
            If Not wbold.Worksheets(OldSheetName).Cells(j, 1).Value = "" Then
                If strValueA = wbold.Worksheets(OldSheetName).Cells(j, 1).Value Then
                    If strValueB = wbold.Worksheets(OldSheetName).Cells(j, 2).Value Then
                        wbold.Worksheets(OldSheetName).Range(Cells(j, 4), Cells(j, 18)).Copy
                        WBnew.Worksheets(AktivtBlad).Range(Cells(i, intData3)).Paste
                        Exit Do
                    End
                End
            End
            j = j + 1
            If intLastrowData > j - 2 Then
                Exit Do
            End
        Loop
        i = i + 1
    Loop

我希望它可以将strValueA和strValueA与wbold.Worksheets(OldSheetName)的数据进行比较,如果匹配则可以从wbold复制数据并将其放入WBnew。 但是它不会编译内部的Do,直到Loop。

1 个答案:

答案 0 :(得分:1)

这很容易:它是End If,而不是End