Excel InputBox Function: Obtain Inputs from a User | Excel Help
Your Programming and Traning Professionals

Excel InputBox Function: Obtain Inputs from a User


We use the InputBoxExcel function to obtain input from the user. It is important to remember to include proper data validations when receiving any input from the user. That will ensure that the data input is what your program expects it to be.

 

The Basics:

 

InputBox( Prompt for the user , Title for the input box , default response that the user is seeing , X position , Y Position , Help file , Context used with the help file )

Prompt for the user = The prompt that the user sees

Title for the input box = The title for the prompt box

Default response that the user is seeing = The default value that is already populated in the input box

X, Y positions = used to position the input box where you need it

Help File and Context = You can include help file related information for the use by the user

Now let’s look at an example. Let’s say we want to obtain input from the Excel user and then take that input and reverse the string, capturing both the input and output to the active worksheet. Below you will see the Excel worksheet before we starting processing the user input.

Code

 

StringToProcess = InputBox(“Please enter the string to be processed”, “User Input”)   ’Assigns the value entered by the user to a variable

ActiveSheet.Cells(2, 1).Value = StringToProcess    ’The value captured from the user prior to being manipulated

StringToProcess = StrReverse(StringToProcess)     ’Reversing the captured string

ActiveSheet.Cells(6, 1).Value = StringToProcess     ‘Writing the output to a specific cell on the output worksheet

 

Output