
Tips.Net > ExcelTips Home > Macros > VBA Examples > Conditionally Displaying a Message Box
Summary: If you want to display a message box when a particular set of criteria are met, you’ll be interested in the techniques in this tip. The approach discussed here relies on the use of the Change event for a worksheet. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)
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, (has to be noted in absolute terms, such as $C$3), then the message box is displayed.
Tip #2553 applies to Microsoft Excel versions: 97 2000 2002 2003 2007
Tame Your Data! ExcelTips: Filters and Filtering provides all the details necessary to let you manage large sets of data with confidence and ease. Its information-packed pages demonstrate how to use the two types of filters provided by Excel: AutoFilters and advanced filters.
Check out ExcelTips: Filters and Filtering today!
Want to make Excel do even more? The way is easy when you know how to use macros. This great e-book makes it easy. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site