on error msg box help

The following code will return a message box whether or not an error
results from running the macro... what gives?

Sub test()
On Error GoTo errr
Range("a2").Value = Range("A1") / Range("B1")
errr: MsgBox "error", vbOKOnly, Error
End Sub
0
Matthew
11/18/2009 7:41:02 PM
excel.programming 6508 articles. 2 followers. Follow

2 Replies
662 Views

Similar Articles

[PageSpeed] 20

You have to do something else if no error.  Exiting is an option.

Sub test()
    On Error GoTo errr
    Range("a2").Value = Range("A1") / Range("B1")
    Exit Sub
errr:     MsgBox "error", vbOKOnly, Error
End Sub


Gord Dibben  MS Excel MVP

On Wed, 18 Nov 2009 11:41:02 -0800 (PST), Matthew Dyer
<matthew.e.dyer@gmail.com> wrote:

>The following code will return a message box whether or not an error
>results from running the macro... what gives?
>
>Sub test()
>On Error GoTo errr
>Range("a2").Value = Range("A1") / Range("B1")
>errr: MsgBox "error", vbOKOnly, Error
>End Sub

0
Gord
11/18/2009 8:29:12 PM
On Nov 18, 1:29=A0pm, Gord Dibben <gorddibbATshawDOTca> wrote:
> You have to do something else if no error. =A0Exiting is an option.
>
> Sub test()
> =A0 =A0 On Error GoTo errr
> =A0 =A0 Range("a2").Value =3D Range("A1") / Range("B1")
> =A0 =A0 Exit Sub
> errr: =A0 =A0 MsgBox "error", vbOKOnly, Error
> End Sub
>
> Gord Dibben =A0MS Excel MVP
>
> On Wed, 18 Nov 2009 11:41:02 -0800 (PST), Matthew Dyer
>
>
>
> <matthew.e.d...@gmail.com> wrote:
> >The following code will return a message box whether or not an error
> >results from running the macro... what gives?
>
> >Sub test()
> >On Error GoTo errr
> >Range("a2").Value =3D Range("A1") / Range("B1")
> >errr: MsgBox "error", vbOKOnly, Error
> >End Sub- Hide quoted text -
>
> - Show quoted text -

The only reason the msg box doesnt appear with the exit sub command is
because the sub is exited before the msgbox command is reached. can
anyone please explain why a msgbox command in an on error goto command
brings up a msgbox whether or not an error occurs? Would putting this
in a if iserror statement make it work?
0
Matthew
11/18/2009 8:50:39 PM
Reply:

Similar Artilces: