
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
Got the Time? Understanding the ins and outs of working with times and dates can be confusing. Remove the confusion--ExcelTips: Times and Dates is an invaluable resource for learning how best to work with times and dates.
Check out ExcelTips: Times and Dates today!
Add power to your purpose with Excel. A comprehensive 500+ page e-book explains everything you need to know about macros. (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