2015-09-11 121 views
0

我想下面的代碼做評估數據集中的每一行,匹配列35的範圍,然後在正確的標籤粘貼。退出嵌套的「如果」語句

我在與If Not IsError聲明麻煩。在這場比賽中不會發生的實例,我想If Not Then跳過剩餘的嵌套代碼,並跳轉到For循環的結束,移動到下一行iRow

Sub testFind()  
    Dim csCount As Range 
    Dim b As Variant 
    Dim shrow As Long 
    Dim iRow As Long, iRowL As Long, var As Variant 
    Dim bln As Boolean 
    Dim s As String 
    Dim eRow As Integer 

    Set csCount = Worksheets("Input").Range("csCount") 
    iRowL = Cells(rows.count, 1).End(xlUp).Row 

    For iRow = 2 To iRowL 
     If Not IsEmpty(Cells(iRow, 35)) Then 
      bln = False 
      var = Application.Match(Cells(iRow, 35).Value, Worksheets("Input").Columns(3), 0) 
      If Not IsError(var) Then 
       Sheets("GL008").rows(iRow).copy 
       s = Sheets("GL008").Cells(iRow, 35) 
       Sheets(s).Activate 
       eRow = Sheets(s).Cells(rows.count, 1).End(xlUp).Offset(1, 0).Row 
       ActiveSheet.Paste Destination:=Sheets(s).rows(eRow) 
      End If 
     End If 
    Next iRow 
End Sub 
+0

我並不想退出對,我想退出。如果繼續到For的下一個iRow。 – KM617

+0

http://stackoverflow.com/questions/5895908/continue-for-loop – CinCout

回答

1

使用CvErr

而不是

If Not IsError(Var) Then 
    ' 
    '~~> Rest of the code 
    ' 
End If 

使用本

If Not CVErr(Var) = CVErr(xlErrNA) Then 
    ' 
    '~~> Rest of the code 
    ' 
End If 
+0

SR,這偉大的工作非常感謝你 – KM617

+0

很高興能幫助:) –

+0

沒問題,我在哪裏可以做到這一點? – KM617