I have a macro that uses an input box to get some data from the user. I used a OK/cancel button - what is the code to kill the macro if the user selects cancle?
thanks
Sub test()
myReply = msgbox("Text", vbOKCancel, "Title")
If myReply = vbCancel Then GoTo TheyPressedCancel
'...
'Your Code
'...
TheyPressedCancel:
End Sub
Obviously you can change the variables from myReply and TheyPressedCancel to whatever you want.
[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]
Help us help you. Please read FAQ181-2886 before posting.
I did make a few changes -
Since I am using an input box to capture a string of data, I ended up coding the cancel button like this:
Code:
Dim inp
inp = Application.InputBox("Input MM_DD" , "Input Required")
' Check to see if Cancel was pressed.
If inp <> False Then
' MAIN CODE HERE
' END OF MAIN CODE
End If
Exit Sub
Note: inp was originally dimensioned as a string, however it must be a var now because if the "If inp <> False Then"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.