Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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.

Using InputBox to Get Data

Written by Allen Wyatt (last updated December 20, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


3

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:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Determining the Number of Paragraphs in a Document

When using a macro to process a document in some way, you often need to know the number of paragraphs in the document. ...

Discover More

Deleting Caption Labels

Define a custom label to be used for captions, and you may later want to delete that label. Here's how you can easily ...

Discover More

Noting the Current Style

One of the drawbacks of the ribbon interface used in Word is that it can be difficult to easily see what style is applied ...

Discover More

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!

More ExcelTips (ribbon)

Creating an Animated Count Up

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 More

Automating Copying Macros

You can manually copy macros from one workbook to another, but what if you want to automate the copying process? Here's ...

Discover More

Counting Atoms in a Chemical Formula

Chemical formulas use a notation that shows the elements and the number of atoms of that element that comprise each ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 4?

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.


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.