Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Application.InputBox usage

typed it too fast! Put the MsgBox myNum in wrong place!!

Sub GetNumber()
Dim myNum As Variant

Application.DisplayAlerts = False

myNum = Application.InputBox(Prompt:="Enter A Number", Title:="Enter A
Number", Type:=1)

If VarType(myNum) = vbBoolean Then

If myNum = False Then
Debug.Print "cancelled"

MsgBox ("Cancel was chosen. Macro will end.")


End If

Else

MsgBox myNum

End If



Application.DisplayAlerts = True

End Sub
--
jb


"john" wrote:

this may do what you are looking for:

Sub GetNumber()
Dim myNum As Variant

Application.DisplayAlerts = False

myNum = Application.InputBox(Prompt:="Enter A Number", Title:="Enter A
Number", Type:=1)

If VarType(myNum) = vbBoolean Then
If myNum = False Then
Debug.Print "cancelled"

MsgBox ("Cancel was chosen. Macro will end.")


Else

MsgBox myNum

End If

End If

Application.DisplayAlerts = True

End Sub

--
jb


"ArthurJ" wrote:

I want the user to input a number. I want to handle the three possible
situations:
1. User enters number
2. User clicks Cancel
3. User enters nothing and clicks OK

I am having trouble with the third possibility, where the user enters nothing.

Below is some of the code I have now:

Sub GetNumber
Dim myNum As Variant
On Error Resume Next 'This line seems to have no effect.
myNum = Application.InputBox(Prompt:="Enter a number", Type:=1)
'If user enters nothing and clicks OK, Excel generates an info box about
'entering an incorrect formula. But it is NOT a VBA error so cannot be
trapped
'with normal methods.

If myNum = False Then
MsgBox ("Cancel was chosen. Macro will end.")
Exit Sub
Else
MsgBox (myNum)
End If
End Sub

Thank you,
Art

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Application.InputBox(,,,,,8) JsJ_Slim Excel Programming 3 August 8th 08 02:32 AM
Application.InputBox Steven Excel Programming 2 December 23rd 06 11:56 PM
Inputbox and Application.InputBox Maria[_7_] Excel Programming 1 September 20th 04 11:36 AM
Application.DecimalSeparator usage. Beto[_3_] Excel Programming 4 March 1st 04 04:29 PM
application.inputbox Murat Excel Programming 4 February 24th 04 11:38 AM


All times are GMT +1. The time now is 11:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"