The InputBox Function
varName = InputBox(Prompt, Title, Default, Xpos, Ypos, HelpFile, Context)
Prompt - (mandatory) the message that will display in the dialog box (up to 1,024) characters long)
Title - The text that appears in the dialog box title bar
Default – The default value that will display in the input box when it first appears. This should normally be provided as a guide for the user. If you omit Default the text box will be empty.
Xpos – The horizontal position of the dialog box from left edge of the screen (measured in points)
Ypos – The vertical position of the dialog box from the top of the screen (measured in points)
HelpFile – The help file used to display the custom help for this dialog box
Context – The number identifying the help in the help file.
The InputBox Method
Using the InputBox method is more versatile then the InputBox function. And allows you to specify the data type or types you want returned. It takes the structure:
varName = Application.InputBox(Prompt, Title, Default, Xpos, Ypos, HelpFile, Context)
The type argument at the end of the argument list determines the type of data that will be returned if you omit Type VBA assumes the data type will be text.
The various data types and their respective values are shown below.
0 – Formula
1 – Number
2 – Text (this is the default)
4 – Boolean
8 – Reference to a range
16 – Error value
32 – Array of Values
This code below is an example of the InputBox Function. When you run this code a box will appear asking the user for the number of the month. It will have a default value of the current month it when display the month in cell D1.