27. VBA Tips - Inputbox
A way to ask a user of your system a question is to use an Inputbox:
Here's what we're trying to achieve:
Ask the question:
Display the answer:
Here's the code:
Explanation:
- InputBox takes several arguments:
- Prompt
- Title
- Default
- Xpos
- Ypos
- HelpFile
- Context
- In this example, we have entered:
- Prompt: "How Many Apples Do You Want?"
- Title: "Apples"
- Default: 3
- We then display the choice back to the user, but using this in a practical way, we'd trap the answer and use it for something else
- We check whether the return from the box is ""
- If "" then they've pressed the Cancel button, and we should exit.
Download sheet to practise how to use the Inputbox in VBA
Training Video on how to use the Inputbox in VBA:
Attachment | Size |
---|---|
inputbox.xls | 48 KB |
»
- Nick's blog
- Login or register to post comments
- 33715 reads
Input box in a userform
Hi Nick, first of all thank you for creating these blog and share your knowledge.
I have some work to do on Excel in a restaurant. I had created a file that shows the items menu, prices and some other stuff.
Unfortunately I am not an expert at all.
My Job is to create a user form that opens when open a special file;
It should welcome the user and ask if you are:
-a new user (then enable him to enter into the file)
-an existing user but want to enter/modify the months activity
-an existing user, willing to analyse the data in the main menu
In my opinion this is a tricky inputbox, I thought maybe you would know how to handle it.
Anyway thank you very much for your help and consideration.
Blackwater
Can't find anywhere, need help
I have created an INPUT Box however I want the input to be placed in a range in Excel, not have a message box appear.
I have looked everyhwere for this instruction...Can you help?
inputbox
Range("A1").value = NumberOfApples
Funny thing
Thanks so much for your answer. I'm an excel expert but not a VBA wiz at all.
Funny thing happening when I do this....Depending on the number I place in the input box it will place a symbol in A1 like the forward symbol or maximze symbol?????
Sub InputBoxDemo()
NumberOfApples = InputBox("How Many Apples Do You Want?", "Apples", 3)
Range("A1").Value = NumberOfApples
End Sub
Funny thing - Font
Check the font of cell A1 or any other thing like code or conditional formatting on that cell.
create a new forum topic, and
create a new forum topic, and add an example sheet with your problem.
The behaviour is v odd