2012-12-20 86 views
1

錯誤發生時,下面的錯誤處理程序正常工作。但是,如果沒有錯誤,它會正確跳過它,但它會在執行ErrHandler:部分中的代碼時忽略它。有誰能告訴我我做錯了什麼嗎?錯誤發生時執行錯誤處理程序

Sub PopulateDynamicReport() 

Dim getcolumnPDR As Range 
Dim getFieldDescriptionPDR As String 
Dim getFormulaPDR As Variant 
Dim columnletter As String 
Dim myrange As String 

Sheets("Config").Select 

Cells.Find(What:="Field Description", after:=ActiveCell, LookIn:= _ 
     xlFormulas, LookAt:=xlPart, searchorder:=xlByRows, searchdirection:= _ 
     xlNext, MatchCase:=False, SearchFormat:=False).Offset(1, 0).Activate 

Do 
    If ActiveCell <> "" Then 

     Set getcolumnPDR = getcolumn 
     getFieldDescriptionPDR = getFieldDescription 

     If ActiveCell.Offset(0, 1) = "Not Applicable" Then 

      getFormulaPDR = "" 

      On Error GoTo ErrHandler 

      Sheets("Dynamic Report").Cells.Find(What:=getFieldDescriptionPDR, after:=ActiveCell, LookIn:= _ 
      xlFormulas, LookAt:=xlPart, searchorder:=xlByRows, searchdirection:= _ 
      xlNext, MatchCase:=False, SearchFormat:=False).EntireColumn.Copy getcolumnPDR 

      On Error GoTo 0 

      ActiveCell.Offset(1, 0).Activate 

     Else 
      getFormulaPDR = getFormula 
      columnletter = ActiveCell.Offset(0, -1) 

      ActiveCell.Offset(0, 1).Copy Sheets("Pricing Analysis").Cells(FindLastRow, columnletter) 
      Sheets("Pricing Analysis").Activate 
      Cells(FindLastRow, columnletter).Activate 
      ActiveCell.Copy 
      Range(Selection, Selection.End(xlUp)).Select 
      Selection.FillUp 
      Application.CutCopyMode = False 

      Sheets("Config").Activate 

      ActiveCell.Copy getcolumnPDR.End(xlUp) 

      Sheets("Pricing Analysis").Activate 

      getcolumnPDR.EntireColumn.AutoFit 
      getcolumnPDR.End(xlUp).Font.Bold = True 

      Sheets("Config").Activate 

      ActiveCell.Offset(1, 0).Activate 
     End If 


    End If 

    Loop Until ActiveCell = "" 

ErrHandler: 
      MsgBox "Field Description in Config tab not listed on report - please check parameters" 
      Exit Sub 

End Sub 

回答

3

退出小組只是你的錯誤處理代碼開始像這樣前:

Exit Sub 

ErrHandler: 
      MsgBox "Field Description in Config tab not listed on report - please check parameters" 
      Exit Sub 
+1

謝謝JMK。我想我需要在聖誕節期間問聖誕老人戴眼鏡..... !!!!!! – user1624926

相關問題