Pausing Macros for User Input

by Allen Wyatt
(last updated July 27, 2016)

8

For those who have been around spreadsheet programs for quite some time, you may remember the old {?}~ command that was available in Lotus 1-2-3. This command allows you to pause the macro while the user enters data in the spreadsheet.

Excel doesn't include the same capability, but it does have ways that you can prompt the user for input. The two primary methods are these:

  • MsgBox function. This function displays a dialog box and a set of buttons. When the user clicks on a button, an integer value is returned that indicates the button clicked. Your program can then take action based on the value returned.
  • InputBox function. This function displays a dialog box an allows the user to type a response. Whatever the user types is returned as a string to the macro.

Both of these functions have been discussed in other issues of ExcelTips; I won't go over them again here. Based on the user's input, you can modify what the macro does in any way desired. The only drawback to the functions is that they only return a single, discrete piece of data. In other words, they aren't designed to allow the user to input a range of cells and then continue processing. For instance, if you wanted to ask the user to provide five values destined for five cells, you would need to present an InputBox five times, depositing the user's responses into the desired cells one after the other.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9515) applies to Microsoft Excel 2007, 2010, and 2013.

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

Managing Comments

If you frequently add comments to cells in a worksheet, Excel provides a variety of tools you can use to manage those ...

Discover More

Changing Default Search Settings

Excel provides some great tools for finding information in a worksheet or a workbook. Changing the default settings used for ...

Discover More

Viewing Comments

Adding comments to a document is a normal activity when writing and editing. Once comments have been added, you may wonder ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Creating a Plus/Minus Button

Want a quick way to convert positive values to negative and vice versa? You can create your own plus/minus button by using a ...

Discover More

Macros Run Slower in Newer Excel?

If you run a macro you used in an older version of Excel on a newer system, it may seem like the macro runs slower. Here are ...

Discover More

Showing RGB Colors in a Cell

Excel allows you to specify the RGB (red, green, and blue) value for any color used in a cell. Here's a quick way to see the ...

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}] 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 two more than 4?

2017-01-05 04:59:50

sunil kumar verma

I would like to known excel tips.


2016-07-27 15:54:46

allen@sharonparq.com

There is a fourth option, Michael: Use the search box at the upper-right corner of any page on this site.

This site contains every single tip ever published in 17+ years of weekly publishing about Excel. That's a lot of tips--about 1,800 of them or so at last count. I try very hard not to duplicate information, so the search function is a very handy function to keep in mind.

Sorry for any frustration!

-Allen


2016-07-27 13:17:00

Michael Heavener

I'm new to your tips, so instead of telling me you've covered this before, I suggest several options.

1. Don't whet my appetites and dash my hopes. Just don't bring up the topic in the newsletter.

2. Repeat the whole tip for those of us who haven't seen it before. People who have will understand and move on.

3. Provide links to the tips so we don't get frustrated.

Thanks.
Michael Heavener


2016-07-27 12:09:12

JMJ

On his site, "Chip" Pearson also gives some very interesting means to wait for an user input :
http://www.cpearson.com/excel/WaitFunctions.aspx


2015-05-27 09:13:44

Glenn Case

Patti:

Allen has a search box at the top of each tip page; you can use those to search for the terms of interest, and each will typically get you several related tips. For instance, a search for "MsgBox" produces 10 pages of related tips. Thus, it's not surprising that Allen does not necessarily link to these directly.

Hope this helps you find what you're after. If it does not, feel free to ask a specific question in the comment section of a related tip, or select the "Ask an Excel Question" link on the righthand side of this page under "Helpful Links" if your question is unrelated to the tip.


2015-05-26 19:05:44

Patti

It would have been helpful if you'd at least linked the previous articles for those of us who don't read your blog regularly and simply found your post while looking for the solution!


2014-09-24 13:47:00

Mohammed Khan

Thanks for this tip.
Can you show a full macro before and after
"UserForm1.Show vbModeless
UserForm1.Visible
DoEvents
Loop"

I wil be grateful. Best regards.


2013-12-28 12:14:42

Bill Meyer

To pause a macro and allow users to enter data directly into a worksheet simply create a user form (UserForm1). Then in the macro put:

UserForm1.Show vbModeless
Do While UserForm1.Visible
DoEvents
Loop

When the user form is closed the macro continues execution at the next statement


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.