InputBox Cancel event

R

Rafi

How do I trap a Cancel event on the following code? I have tried the most
common IF statements however, the code blows up before getting to the IF
statement when CANCEL is clicked.

Set rng = Application.InputBox(Msg1, Title1, Type:=8)
 
F

FSt1

hi
if the user clicks cancel, the input box returns a zero length string.
something like this might work.....
if return = "" then
msgbox "nothing entered?!?!"
exit sub '??
end if

play with it.
regards
FSt1
 
M

Mike H

Try

Dim rng As Range
On Error Resume Next
Set rng = Application.InputBox(Prompt:=msg1, Title:=title1, Type:=8)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "User Cancelled"
Exit Sub
End If
' Do lots of things

Mike
 

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