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

Viewing Comments

There are three different ways that Excel allows you to display any comments that are in your worksheet. Here's how you can ...

Discover More

TOC Heading Numbers Always Show in Bold

Linda's got a document that includes a table of contents that is based on headings in the document. When the headings include ...

Discover More

Adjusting Line Spacing

When formatting your document, one of the layout decisions you need to make is how "spread out" your text will be, ...

Discover More

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!

More ExcelTips (ribbon)

Finding Columns of a Certain Width

If you need to find out how many columns are set to be a specific width, you'll need a macro to help determine the info. ...

Discover More

Converting Numbers to Strings

When creating macros, it is often necessary to change from one type of data to another. Here's how you can change from a ...

Discover More

Bypassing the BeforeClose Event

Hold down the Shift key as you open a workbook, and Excel bypasses any "startup macros" that may be in the workbook. If you ...

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 8Mpixels. 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 6 - 3?

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.