Error handling on input box

spurs

Active Member
Joined
Oct 18, 2006
Messages
479
Office Version
  1. 2016
  2. 2013
  3. 2010
  4. 2007
  5. 2003 or older
Platform
  1. Windows
I am trying to create an input box (or something like it)
InputBox has 2 buttons ok and cancel. I don't need the cancel but someone could press it.

I have an error handler in case the numerical value entered is out of range.
d is an initial value

In my code below if cancel is pressed during input it seems that false is not returned as i get the Mesage Box "Error- The selected " & dy & " mm diameter is not in range." returned instead

How can I fix this?

Sub Test
On Error GoTo errHandler
dy = InputBox("Enter a Diameter of Interest", "Parameters", d)


errHandler:
If dy = "False" Then Exit Sub

MsgBox "Error- The selected " & dy & " mm diameter is not in range.", vbOKOnly
Exit Sub
Resume

Exit Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
try this

VBA Code:
Sub Test()
d = 10 'sets the dafualt value
dy = Application.InputBox("Enter a Diameter of Interest", Default:=d, Type:=1) 'type 1 means must be numberic
If dy = "False" Then Exit Sub

'.....
End Sub
 
Upvote 0
try this

VBA Code:
Sub Test()
d = 10 'sets the dafualt value
dy = Application.InputBox("Enter a Diameter of Interest", Default:=d, Type:=1) 'type 1 means must be numberic
If dy = "False" Then Exit Sub

'.....
End Sub
Thank you for your help
 
Upvote 0

Forum statistics

Threads
1,215,095
Messages
6,123,072
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top