View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
George Nicholson[_2_] George Nicholson[_2_] is offline
external usenet poster
 
Posts: 170
Default Inputbox question

Two possible approachs:

1) If you want them to explicitly specify that they want to cancel:

Do While strTemp = ""
strTemp = InputBox("Enter a value or CANCEL to Abort...",
"MyCaption", "MyDefault")
Loop

Select Case uCase(Trim(strTemp))
Case "CANCEL"
Exit Sub
Case Else
' Do something else
End Select

2): If you don't want to be that demanding (and relying on fact that the
InputBox returns an empty string if nothing is input):

strTemp = InputBox("Enter a value or CANCEL to Abort...", "MyCaption",
"MyDefault")

Select Case uCase(Trim(strTemp))
Case "CANCEL", ""
Exit Sub
Case Else
' Do something else
End Select

HTH,
--
George Nicholson

Remove 'Junk' from return address.


"wilro85" wrote in
message ...

When using an inputbox, how do you keep it from generating an error if
the user clicks cancel? I want them to be able to cancel it, just not
have to think about whether they should end or debug.

So far I've had no luck with things such as

....
if VBcancel then end
elseif
....

because that cuts my program short. What is the trick?


--
wilro85
------------------------------------------------------------------------
wilro85's Profile:
http://www.excelforum.com/member.php...o&userid=26935
View this thread: http://www.excelforum.com/showthread...hreadid=466059