-
Solved: Set Msgbox with Default number?
Hi,
I'm new to VBA programming.
How do you write the codes for showing an inputbox asking the user to enter a number, but if the user leaves the box blank, Excel will default it to 35? Can someone help?
I only have these so far:
[vba]Dim Age as Double
Age = InputBox("Please Enter Your Age" & vbCrLf & "Default: 35")[/vba]
Last edited by doctortt; 03-28-2011 at 12:03 AM.
-
Welcome to VBA Express.
One of the forum practices (rules) here is wrapping all code, even snippets like the one above. I fixed it this time.
This uses Application.InputBox and the Type argument to validate the user's entry.
[VBA]Dim Age As Double
Age = Application.InputBox("Enter your age.", Default:=35, Type:=1)
If Age = 0 Then
MsgBox "Cancel pressed"
Else
MsgBox Age & " entered."
End If[/VBA]
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules