简体   繁体   English

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

[英]A Do until loop nested in a do while loop that doesn't compile in excel VBA

The code doesn't compile and shows a fault in the Do until loop. 该代码无法编译,并在Do直到循环中显示错误。 It says that there is a loop with out a do. 它说有一个循环,没有执行。 There is more code the this and that works fine and i have Option Explicit in top of the module. 这里有更多代码,可以正常工作,并且模块顶部有Option Explicit。 The fault marker is tagging the 2 to last Loop. 故障标记将2标记为最后一个循环。 What am i missing? 我想念什么?

I've tried to put the code in a separate sub i've tried 我试图将代码放在我尝试过的单独子中


    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

I expect it to compare the strValueA and strValueA with data from wbold.Worksheets(OldSheetName) and if it matches to copy data from wbold and pase it in WBnew. 我希望它可以将strValueA和strValueA与wbold.Worksheets(OldSheetName)中的数据进行比较,如果它匹配以从wbold复制数据并将其放入WBnew中,则将其匹配。 But it doesn't compile the the inner Do until Loop. 但是它不会编译内部的Do直到Loop。

这很简单: End If ,而不是End

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM