ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   InputBox Cancel event (https://www.excelbanter.com/excel-programming/423703-inputbox-cancel-event.html)

Rafi

InputBox Cancel event
 
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)

FSt1

InputBox Cancel event
 
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
"Rafi" wrote:

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)


Mike H

InputBox Cancel event
 
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

"Rafi" wrote:

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)



All times are GMT +1. The time now is 12:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com