Excel Easy
#1 Excel tutorial on the net Excel Introduction Basics Functions Data Analysis VBA 300 Examples Ask us
InputBox Function Search Entire Site Go
You can use the InputBox function in Excel VBA to prompt the user to enter a value. Place a command button on
your worksheet and add the following code lines: Chapter < >
1. First, declare the variable myValue of type Variant. MsgBox
Dim myValue As Variant
Note: we use a variable of type Variant here because a Variant variable can hold any type of value. This way the Learn more, it's easy
user can enter text, numbers, etc.
MsgBox Function
InputBox Function
Download Excel File
inputbox[Link]
Follow Excel Easy
2. Add the following code line to show the input box.
myValue = InputBox("Give me some input")
3. Write the value of myValue to cell A1.
Range("A1").Value = myValue
Result when the user enters the value 5 and clicks the OK button.
4. The InputBox function has more optional arguments. The following code line shows an input box with a title
displayed in the title bar and has a default value. The default value will be used if no other input is provided.
myValue = InputBox("Give me some input", "Hi", 1)
Result when the user only clicks the OK button.
Note: Place your cursor on InputBox in the Visual Basic Editor and click F1 for help on the other optional
arguments.
3/3 Completed! Learn much more about msgboxes >
Back to Top: InputBox Function | Go to Next Chapter: Workbook and Worksheet Object
EXCEL EASY • FREE EXCEL HELP • COPYRIGHT (C) 20102017 • ALL RIGHTS RESERVED
MICROSOFT EXCEL TUTORIAL | HOW TO USE VBA | EXCEL FORMULAS | DROPDOWN LIST