InputBox: Separate CANCEL and 0

M

Mike

I want to program an InputBox for numbers. A valid entry is 0. I also want to
exit the routine in case the user pushes CANCEL.

Is there a way to differentiate the CANCEL and 0? My current code is as
follows. However, if the user pushes 0, it exits even though I do not want it
to.

myMinScale = Application.InputBox(prompt:="Enter MINIMUM Value for the
Y-axis", Type:=1)
' Check if user pushed "Cancel"
If myMinScale = False Then
GoTo End_AxisMinMax_SetManually
End If

Thanks!
 
R

Ron Coderre

If the user clicks [Cancel], or does not input any value and clicks [OK], the
InputBox returns an empty string "".....as demonstrated below:


Sub TestInputbox()
Dim vRetVal
vRetVal = InputBox(Prompt:="Enter something: ")
If vRetVal = "" Then
MsgBox "You pressed [Cancel] or entered nothing."
Else
MsgBox "You entered: " & vRetVal
End If
End Sub

Is that something you can work with?
***********
Regards,
Ron

XL2003, WinXP
 
M

Mike

Thank you so much! This works!

Ron Coderre said:
If the user clicks [Cancel], or does not input any value and clicks [OK], the
InputBox returns an empty string "".....as demonstrated below:


Sub TestInputbox()
Dim vRetVal
vRetVal = InputBox(Prompt:="Enter something: ")
If vRetVal = "" Then
MsgBox "You pressed [Cancel] or entered nothing."
Else
MsgBox "You entered: " & vRetVal
End If
End Sub

Is that something you can work with?
***********
Regards,
Ron

XL2003, WinXP


Mike said:
I want to program an InputBox for numbers. A valid entry is 0. I also want to
exit the routine in case the user pushes CANCEL.

Is there a way to differentiate the CANCEL and 0? My current code is as
follows. However, if the user pushes 0, it exits even though I do not want it
to.

myMinScale = Application.InputBox(prompt:="Enter MINIMUM Value for the
Y-axis", Type:=1)
' Check if user pushed "Cancel"
If myMinScale = False Then
GoTo End_AxisMinMax_SetManually
End If

Thanks!
 
C

Chip Pearson

In case you want to distinguish between clicking OK with no input and
clicking Cancel, use code like the following:

Dim S As String
S = InputBox("Enter Something")
If StrPtr(S) = 0 Then
Debug.Print "You clicked cancel"
ElseIf S = vbNullString Then
Debug.Print "You entered nothing"
Else
Debug.Print "You entered: " & S
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


Ron Coderre said:
If the user clicks [Cancel], or does not input any value and clicks [OK],
the
InputBox returns an empty string "".....as demonstrated below:


Sub TestInputbox()
Dim vRetVal
vRetVal = InputBox(Prompt:="Enter something: ")
If vRetVal = "" Then
MsgBox "You pressed [Cancel] or entered nothing."
Else
MsgBox "You entered: " & vRetVal
End If
End Sub

Is that something you can work with?
***********
Regards,
Ron

XL2003, WinXP


Mike said:
I want to program an InputBox for numbers. A valid entry is 0. I also
want to
exit the routine in case the user pushes CANCEL.

Is there a way to differentiate the CANCEL and 0? My current code is as
follows. However, if the user pushes 0, it exits even though I do not
want it
to.

myMinScale = Application.InputBox(prompt:="Enter MINIMUM Value for
the
Y-axis", Type:=1)
' Check if user pushed "Cancel"
If myMinScale = False Then
GoTo End_AxisMinMax_SetManually
End If

Thanks!
 

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