Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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: Conditionally Displaying a Message Box.

Conditionally Displaying a Message Box

by Allen Wyatt
(last updated February 15, 2014)

2

You may have a need to display a message box whenever specific information is placed in a specific cell by the user. Fortunately, using the Change event for a worksheet can help you to figure out when something has been placed in a cell.

For instance, let's say that you wanted to displays a message whenever the information in cell C3 is changed. The following, added to the code window for a specific worksheet, will do the trick:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$C$3" Then
        MsgBox "Changed It!"
    End If
End Sub

The Change event is called, and passes the cell range to the routine. In this case, the range is assigned to the Target variable. The address of this range is then checked, and if it is equal to C3 (it has to be noted in absolute terms, such as $C$3), then the message box is displayed.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9397) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Conditionally Displaying a Message Box.

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

Checking for the Existence of a File

The data stored in a worksheet can often correspond to information external to that worksheet. For instance, you might ...

Discover More

Changing the Start Screen's Theme

You'll spend a lot of time viewing the Start screen in Windows. If you want to change up things, you can modify which theme ...

Discover More

Comments in Endnotes

Able to add comments everywhere, except in endnotes? This seems to be a limitation in Word, but here are some ways to work ...

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)

Removing a Macro from a Shortcut Key

When you assign a macro to a shortcut key, you make it easy to run the macro without ever removing your hands from the ...

Discover More

Using SUM In a Macro

Want to use a worksheet function (such as SUM) from within a macro? Here's how easy it is to accomplish the task.

Discover More

Counting Empty Colored Cells

There are a variety of ways that you might want to count the cells in your worksheet. One way is to figure out how many of ...

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. 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 nine minus 5?

2017-05-02 11:54:32

Paolo Gera

I need to display a message when any cell of a specific range of adjacent cells is changed. Is there any means of doing this by altering the code presented in this tip?
Thanks in advance...


2014-07-30 16:08:24

Dennis Costello

I believe (although I did not experiment to confirm this) that this technique will not respond when the change is to a range of cells. If, for instance, the Excel user were to paste in an array of values into the range A2:D5, which clearly includes cell C3, the Worksheet_Change macro would have Target.Address as "$A$2". You need to check whether the the cell of particular interest lies within the Range. And possibly also take into account that the range might contain multiple areas.


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.