Written by Allen Wyatt (last updated December 20, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12496) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Using InputBox to Get Data.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
When working with data in a macro, there are two broad categories you can manipulate: numbers and text. Sometimes you ...
Discover MoreIf you develop some handy macros that you use on your system, you may want to share those macros with others. This tip ...
Discover MoreEven if you do nothing but record macros, sooner or later you will have a need to edit what you record. Here's how to get ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-12-28 10:18:03
J. Woolley
My Excel Toolbox includes the InputBoxVBA_Custom and InputBoxApp_Custom functions. Both allow positioning that can be either the location of a worksheet's cell or absolute screen coordinates. The standard InputBox functions only permit the latter.
See https://sites.google.com/view/MyExcelToolbox/
2021-12-27 08:29:26
Ferreira
I reda every day, they are fantastic, thanks a lot
2021-12-20 08:48:07
Kiwerry
Thank you, Allen
Quick addition:
be aware that apart from the InputBox mentioned by Allen (and described in detail on https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/inputbox-function ),
there is an application specific Inputbox (described in
https://docs.microsoft.com/en-us/office/vba/api/excel.application.inputbox)
which operates in a very similar way, but has an advantage for some situations in that the Type of the input (e.g. Text, or Numbers) can be restricted; If the Type is set to 1, for example, the InputBox won't accept a string.
Note also that the InputBox returns "" if Cancel is pressed, but the Application.InputBox returns False.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments