Coding: Basic Input Box in VBA

February 22, 2011


I hope you guys enjoyed the first VBA tutorial that I have posted. I decided to create another tutorial for beginners; this one will have you create an input box asking for your name. Once you enter your name, a message box will appear telling you what your name is. You can change this basic code any way you want to suite your needs. Let’s get started:

1. Launch Excel and select the “Developer” tab, if you do not see the tab then do the following:

  • Click on the Office button and select “Excel Options” and then check the “Show Developer tab in the ribbon” check box.

2. Once you selected the “Developer” tab, click on “Visual Basic”.

3. A new window will open up (“Microsoft Visual Basic”), there you will click “Insert” and select “Module”.

4. Type the following code (told you I will make it simple):

Sub userEntry()

Dim userInput As String

userInput = InputBox(“Enter your name”)
MsgBox “Your name is ” & userInput & “.”

End Sub

  • Just an FYI, once you finish the first line, the “End Sub” will automatically be added.

5. Press F5 to execute your code, and you are done!


6. Save the worksheet as an Excel Macro-Enabled Workbook.

I hope I made this tutorial as simple as possible for the readers that never did anything with VBA before.