|
|
| Back to Excel Homepage | Excel VBA - Reference Guide |
|
Menu VBA Input Box
Other links
|
An Input Box (InputBox) is a function that allows the user to enter a value into a dialog box. The result of an Input Box is stored normally to a variable and remebered for later use in a procedure. Note that the result of an Input Box is always returns a String value.
Structure (syntax): Variable = InputBox (Prompt, [Title], [Default], [XPos], [YPos])
The Arguments for an InputBox:
Example1 - Text Input Box:
If you click on the Cancel button, it will return an empty string " " so the result will be "My name is"
Example2 - Using named arguments: This allows you to put the arguments in any order.
You really need to handle the Cancel button which always returns an empty String. Even if you click the OK button with no value this too will return an empty String.
In most cases, the following code should be added immediately after the InputBox function call:
If [Variable] = Empty Then Exit Sub
The above piece of code will terminate the procedure if the String variable is empty. So the the previous example would look like:
While a the InputBox function s being displayed, the macro procedure is paused waiting for the user to click a button.
|
VBA Keyword: InuptBox, ActiveCell, If...Then, Exit Sub |
|
© copyright 2010 TP Development & Consultancy Ltd, All Rights Reserved. All trademarks are copyrighted by their respective owners. Please read our terms of use and privacy policy. |