Application.InputBox with Default:=0 testing False

B

bluhme

Hi,

I am looking for help with the Application.InputBox in Excel. I want t
force the user to enter a number which default is 0. However I also wan
to check if the user press 'Cancel'. So my current code is somethin
like:

Temp = Application.InputBox("Input number:", "Input", 0, , , , , 1)
If Temp = False Then
Exit Sub
Else
'other code'
End If

However if I just hit 'Enter' with the default value, or enters '0' an
then 'Enter', my test ends the sub despite that a valid number (0) wa
entered. How do I avoid this conflict between the InputBox returnin
False on 'Cancel' and a value of '0' being read as False in the test?

Cheers

Bluhme
 
N

NickHK

Bluhme,
Unless anyone has a better way:

Temp = CStr(Temp)
If IsNumeric(Temp) Then

NickHK
 
R

Rob van Gelder

Sub test()
Dim var As Variant

var = Application.InputBox("Input number:", "Input", 0, , , , , 1)
If VarType(var) = vbBoolean Then Exit Sub

MsgBox var
End Sub
 

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