Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Using InputBox to Get Data.
by Allen Wyatt
(last updated August 23, 2016)
If you are developing a simple custom application in Excel, you may want to use the InputBox function to retrieve information from the user, and then place that information in a particular place in a worksheet. This can be easily done in the following manner:
UserValue = InputBox("Value to use?") Cells(1, 1).Value = UserValue
These two lines, when inserted into a macro, prompt the user for input. This input is assigned to the UserValue variable by the InputBox function. The contents of this variable are then deposited in cell A1 of the current worksheet using the Cells method. If you prefer, you could also use the Range object to specify a location for the value, as shown here:
UserValue = InputBox("Value to use?") Range("B3").Value = UserValue
This example deposits the value of UserValue into cell B3.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12496) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Using InputBox to Get Data.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
What is a macro? Ever wonder what these are and how to use them? This tip answers the basics of what a macro is used for, ...Discover More
Ever wonder what the macro-oriented equivalent of pressing Ctrl+End is? Here's the code and some caveats on using it.Discover More
Got a macro that you need to run on each of a number of workbooks? Excel provides a number of ways to go about this task, as ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.