Cancel button on messagebox/inputbox

G

Greg

I am just wondering how to stop this from happening.

I have a series of question on a inputbox and when i click the cancel button
it just goes to the next one in line. How do I get excel to go back to the
userform called "main" when either the cancel or the x button is pressed?

Also will this work on a messagebox as well?

Thanks in advance

Greg
 
N

NickHK

Greg,
You need to check the return value. e.g.

If MsgBox("Is this [Some Value] correct ?", vbYesNoCancel) = vbCancel Then

With Input boxes, it depends which you are using. According to Help :
1 - VBA.InputBox Function, "If the user clicks Cancel, the function returns
a zero-length string ("")."
2 - Application.InputBox Method, "If you click the Cancel button, InputBox
returns False."

NickHK
 

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