VBA InputBox – Get Input from a User

VBA InputBox

The VBA InputBox allows you to prompt the user to input information.  That information is assigned to a variable and can be used in your code.

Here is how you can create an InputBox:

vba inputbox

Notice first we declare a variable. This variable will be assigned the value that the user enters.  We used variable type Variant so the InputBox can accept any type of value.

Get Input from a User

Here is another example using the most popular features of an InputBox.

tiphacks3

The following code does three things:

1. Prompts for input with an InputBox and assigns it to a variable

2. Verify’s input, otherwise exits

3. Returns the input in a message box

Returning the input to an Excel Sheet

You can return the input that you type into an input box into a specific cell in your Excel sheet.

vba input box enter

 

Using VBA InputBox in Access VBA

The VBA input box works exactly the same way in Access as it does in Excel when returning user input in the form of a message box.

However, if you wish to return the user input to the database, you would need to use the Recordset object rather than the Range object as used in Excel.

vba inv no

 

 

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

 

Learn More!


<<Return to VBA Examples

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)