编译错误:结束时不带。但是那里有

时间:2015-10-27 11:46:32

标签: vba excel-vba excel

对于我的工作代码,我不得不使用新的With EndWith。不,我不能再运行它了,第二个EndWith导致错误。编译错误:结束时不带。我也尝试过嵌套With EndWith,它没有用。任何的想法?谢谢你的帮助!

这是代码的必需部分:

 With wsSrc
        LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        For j = 0 To UBound(SearchValues)
            For i = 2 To LastRow
                If .Cells(i, 1).Value = SearchValues(j) Then

                    wsDest.Range("A" & z).Value = .Range("A" & i).Value
                    wsDest.Range("B" & z).Value = .Range("N" & i).Value
                    wsDest.Range("C" & z).Value = .Range("O" & i).Value
                    wsDest.Range("D" & z).Value = .Range("AM" & i).Value
                    wsDest.Range("G" & z).Value = .Range("AH" & i).Value
                    wsDest.Range("I" & z).Value = .Range("P" & i).Value
                    wsDest.Range("J" & z).Value = .Range("E" & i).Value
                    wsDest.Range("K" & z).Value = .Range("F" & i).Value

                    z = z + 1

                End If
            Next i
        Next j
   End With
    With wsSrc2
        LastRow2 = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            For k = 2 To LastRow2
                If .Cells(i, 1).Value = "724" Then
                    wsDest.Range("B" & z).Value = .Range("N" & k).Value
                    wsDest.Range("C" & z).Value = .Range("O" & k).Value
                    wsDest.Range("D" & z).Value = .Range("AM" & k).Value
                    wsDest.Range("G" & z).Value = .Range("T" & k).Value
                    wsDest.Range("I" & z).Value = .Range("P" & k).Value
                    wsDest.Range("J" & z).Value = .Range("E" & k).Value
                    wsDest.Range("K" & z).Value = .Range("F" & k).Value
                    wsDest.Range("A" & z).Value = "724"
                    z = z + 1
                End If
    End With

1 个答案:

答案 0 :(得分:1)

底部For Loop

中缺少你的下一个