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.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
You might want to display a value in a cell as an upward-counting value. This might seem difficult but can be done rather ...
Discover MoreYou can manually copy macros from one workbook to another, but what if you want to automate the copying process? Here's ...
Discover MoreChemical formulas use a notation that shows the elements and the number of atoms of that element that comprise each ...
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