下一步没有For错误消息

时间:2014-03-13 21:54:33

标签: vba

每当我运行下面的代码时,我会不断获取Next而不会出现错误信息 - 任何想法可能导致它?

Sub VDA_Update()

Dim wshT As Worksheet
    Dim wbk As Workbook
    Dim wshS As Worksheet
    Dim r As Long
    Dim m As Long
    Dim cel As Range
    Application.ScreenUpdating = False
    Set wshT = ThisWorkbook.Worksheets("Master")
    On Error Resume Next

    ' Check whether vda.xlsx is already open
    Set wbk = Workbooks("vda.xlsx")
        On Error GoTo 0
        If wbk Is Nothing Then
        ' If not, open it
        Set wbk = Workbooks.Open("C:\Working\vda.xlsx")
    End If

    ' Set worksheet on vda.xlsx
    Set wshS = wbk.Worksheets("remotepclist")
    m = wshT.Cells(wshT.Rows.Count, 1).End(xlUp).Row

    ' Loop though cells in column J on main.xlsm
    For r = 1 To m

        For cCtr = 0 To 2

        ' Can we find the value in column A of vda.xlsx?
          Set cel = wshS.Columns(1).Find(What:="EMEA\" + wshT.Cells(r, 10 + cCtr).Value, _
          LookAt:=xlWhole, MatchCase:=False)

          If Not cel Is Nothing Then

              ' If we find a match, then change cell color
              If cel.Offset(0, 1).Value = "TRUE" Then
                  wshT.Cells(r, 10 + cCtr).Interior.ColorIndex = 15
              ElseIf cel.Offset(0, 1).Value = "FALSE" Then
                  wshT.Cells(r, 10 + cCtr).Interior.ColorIndex = 6

                  If wshT.Cells(r, 15).Value = "" Then wshT.Cells(r, 15).Value = "Yes"

                  If wshT.Cells(r, 16).Value = "" Then wshT.Cells(r, 16).Value = "5.6.200"

              End If

        Next cCtr

    Next r

    Application.ScreenUpdating = True

End Sub

1 个答案:

答案 0 :(得分:2)

您尚未关闭If声明。您需要End If之前的Next ctr

(顺便说一下,你的缩进对你没有帮助。)