Cancel buttons in Msgbox

P

Paula O.

I am having one of the brain-blanks. For some reason,
when you click the cancel button on several of my msg or
input boxes, it does not cancel the function, but returns
to the loop. What do I do to get the cancel buttons to
function normally...?
 
S

steve

Paula,

The message box will return 2 or vbCancel when you click the
cancel button.

So
Dim x
x = Msgbox("Prompt",vbOKCancel)
If x = vbCancel then ' or = 2
exit sub
end if

You can use something like this to check
Dim x
x = MsgBox("adfjjsdf", vbOKCancel)
MsgBox x
 
P

Patrick Molloy

Sub MessageBoxCheck()
If MsgBox("Continue?", vbQuestion + _
vbOKCancel, "Test") = vbCancel Then
MsgBox "Cancelled"
Exit Sub
End If
'
' you process here
'
MsgBox "Processed"
End Sub


Patrick Molloy
Microsoft Excel MVP
 

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