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

Conditionally Displaying a Message Box

by Allen Wyatt
(last updated November 23, 2019)


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 display 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.


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 (9397) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. 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. ...


Problem with Missing Context Menu Option

When you right-click a cell, does it seem that the Context menu is missing an item or two? Here's how to get those items ...

Discover More

Easily Changing Links in Documents

You may have a lot of linked images in a document, and then one day need to change the links if the location of the ...

Discover More

Using Text Boxes

Text boxes are handy for placing information in a container that can "float" over your worksheet. This tip explains what ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Creating a String in a Macro

Need to put together a bunch of characters to create a text string? You can do it in your macros by using the String ...

Discover More

Generating a Keyword Occurrence List

Need to pull a list of words from a range of cells? This tip shows how easy you can perform the task using a macro.

Discover More

Generating a List of Macros

Got a workbook that has lots and lots of macros associated with it? Here's a way you can get a list of all of those ...

Discover More

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

View most recent newsletter.


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 nine minus 2?

2018-04-20 05:56:35

Ruthie A. Ward

@Chuck Trese: Thanks
@Alan Elston: Didn't know about Intersect - new knowledge always appreciated!

2018-04-18 03:45:22

Alan Elston

@ Chuck Trese
Nice clear explanation :-)

@ Ruthie A. Ward
Are you aware that Target is the selected / changed range? – Effectively, “behind the scenes” , when a change occurs anywhere in a Worksheet, then VBA does something pseudo like this
Set Target = range of cells changed

I could not quite follow what you were proposing

Alan Elston

2018-04-17 13:19:02

Chuck Trese

regarding below post...
Of course, Range("C3") can be replaced with any range (single cell, contiguous cells, non-contiguous cells, named range, union, intersection, ......) to suit your needs.

2018-04-17 10:35:20

Chuck Trese

Ok, maybe an explanation is called for here:
If Not Intersect(Target, Range("C3")) Is Nothing Then

I first saw this somewhere on the internet years ago, been using it ever since.
The "Target" range is the cells selected by the user at the time of the change event.
The Intersect function will give you the intersection (overlap) between two ranges.
If the two do not overlap, then the intersection will be Nothing.
If the Intersection is Not Nothing, then there is an intersection, which means cell C3 is somewhere within the Target range.
That would mean cell C3 was just changed.

This works regardless of the shape of the Target range.
pretty cool, eh?

2018-04-17 10:04:42

Chuck Trese

@ Ruthie,
It's actually a LOT easier than that. You can use this construct:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C3")) Is Nothing Then
MsgBox "Changed It!"
End If
End Sub

2018-04-17 09:42:31

Ruthie A. Ward

If you want to check a specific range, adding a loop to check each cell's address against the target address should work. To check non-specific ranges, select the desired ranges and use the loop to check each cell's address against your target address. In this case, the message box would only display if the cell with the target address is selected. If you combined the two looping checks, you could determine whether or not the target cell was changed with one macro and two nested IF statements. (I'm not good writing loop structures so ... indicates where they should go.)

Private Sub Worksheet_Change(ByVal Target As Range)
' Check loop specific.
...loop specific range
If Target.Address = "$C$3" Then
MsgBox "Changed It!"
' Check if range is non-specific
If ...code to check selected range <> specific range
' Check loop non-specific
...loop non-specific
If Target.Address = $C$3" Then
MsgBox "Changed It!"
End If
...end loop non-specific
End If 'range check
End If
...end loop specific
End Sub

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

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.