View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Avoiding error on Input Box - if no value is entered

Oops..If that is a type mismatch check your declaration and adjust the code
as below to handle blanks

Dim mydata As Integer
mydata = CInt("0" & InputBox(Prompt:="Enter Data", Title:="ENTER Data"))


If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Check the result and Exit Sub

MyData = InputBox(Prompt:="Enter Data", Title:="ENTER Data")
If Trim(MyData) = "" Then Exit Sub

OR

If you want to force the user to enter something then keep this within a loop

Do
MyData = InputBox(Prompt:="Enter Data", Title:="ENTER Data")
Loop Until Trim(MyData) < ""


If this post helps click Yes
---------------
Jacob Skaria


"dhstein" wrote:

I have a line like this:

MyData = InputBox(Prompt:="Enter Data", Title:="ENTER Data")

If the user selects "Cancel", I get a Run-time error 13 - Type Mismatch.
How can I avoid this error when the user selects cancel ? Thanks for any
help on this.