on error msg box help

M

Matthew Dyer

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
 
G

Gord Dibben

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
 
M

Matthew Dyer

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




- 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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top