Cancel buttons in Msgbox

  • Thread starter Thread starter Paula O.
  • Start date Start date
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...?
 
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
 
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
 
Back
Top