vba Error handler to exit

I am trying the code below to handle a run time error.
IF there is an error, show msg box and exit.
I am missing something, because it shows even when the code runs successfully.
Can anyone help?

    Application.ScreenUpdating = False
  On Error GoTo ErrHnd
    ActiveSheet.Name = "Report"

    Dim i As Integer, rngData As Range
    Set rngData = Range("A1").CurrentRegion
    i = Application.WorksheetFunction.Match("Rated Weight", Range("A1:AZ1"), 0)

    rngData.AutoFilter Field:=i, Criteria1:="<" & Sheets("Details").Range("B3").Value

    Range(Range("A2"), Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False

  MsgBox "There was no data meeting the criteria", vbExclamation, "No Data"

End Sub

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
Put "Exit Sub" on the line prior to ErrHnd:.

You also do not need the END on line 27 unless your desire is to stop all processing.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NorieAnalyst Assistant Commented:
What error are you trying to handle?

Does this do what you want?
Dim i As Variant, rngData As Range

    Application.ScreenUpdating = False
    With Sheets("Report")
        .Name = "Report"
        Set rngData = .Range("A1").CurrentRegion
        i = Application.Match("Rated Weight", .Range("A1:AZ1"), 0)

        If Not IsError(i) Then
            rngData.AutoFilter Field:=i, Criteria1:="<" & Sheets("Details").Range("B3").Value
            On Error Resume Next
            .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).EntireRow.Delete
            On Error GoTo 0

            If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False

            MsgBox "There was no data meeting the criteria", vbExclamation, "No Data"


        End If

    End With

End Sub

Open in new window

Euro5Author Commented:
I did want to stop all processing. Thanks so much!
Martin LissOlder than dirtCommented:
End does not allow Visual Basic to clean up after itself when it stops so you may wind up with parts of the application running in the background, so you should never use End unless there is no other way to do what you want. If all you want to do is to exit the FILTER sub when there's an error then remove the End line. If you want to stop some other sub from running when the FILTER  sub gets an error then create a global Boolean variable and set it to True in FILTER's error routine and check the value in your other sub.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.