Excel Hack 72: Creating input prompts in MS Excel (the Input Box feature)

This is a short post introducing a feature in Excel VBA that enables you to update the contents of any cell through an input box. Just as demonstrated above.

The Input Box is an Excel VBA feature. It can be introduced in macros to request for input from the user to complete an automated task.

There are several applications of the Input Box feature, but one of the simplest usage is what is shown above. You select a cell; click a button; the Input Box appears, asking you what to put in the selected cell; you input a text; and the text shows up in the selected cell. The code below shows how this is done.

Open the Visual Basic Editor in MS Excel (you can use the keyboard shortcut Alt+F11), click Insert and select Module, and put in this code in the new window that appears:

Sub EnterData()

Dim inputData As String

iString = InputBox("Tell me what to put in this cell")
ActiveCell.Value = iString


End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *