Pop-Up Message Box When a Cell Reaches a Certain Value or Contains Certain Text

Add to Favorites

This macro will display a message box in excel when a cell reaches a certain value or contains certain text. This means that when cell A1 contains the value "hi" a message box will pop-up telling the user that cell A1 now contains the word "hi".

This macro can be changed to display a message box whenever a cell meets whatever criteria you want. You can change the criteria to display a message whenever certain text is entered into a cell by changing ,in this line of code, If rng = "hi" Then the "hi" to whatever you want. You can also change the display message to whatever you would like by changing the text inbetween the quotation marks in this code MsgBox "Cell " & _ rng.Address & " = hi". Also, if you want to change the cell to which the value must be entered for a message box to appear, change the A1 in this line of code to whatever you would like Set rng = Range("A1").

This macro is particularly useful in forms in excel. This way you can solicit input from a user and when he/she enters something, you can have a message box appear to remind them of something or to warn the user etc. This is pretty versatile code and is easily modified to check for many different types of values or characters and to then display the pop-up message box in excel.

Where to install the macro:  Worksheet

Pop-Up Message Box When a Cell Reaches a Certain Value or Contains Certain Text

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

Dim rng As Range
   Set rng = Range("A1")
   If Not Intersect(Target, rng) Is Nothing Then
       If rng = "hi" Then
        MsgBox "Cell " & _
         rng.Address & " = hi"
       End If
   End If

   Set rng = Nothing End Sub





Similar Content on TeachExcel
Pop-Up Message Box When a Range of Cells Reaches a Certain Average
Macro: This macro will display a message box when the numbers within a range of cells reaches...
Excel Data Validation - Limit What a User Can Enter into a Cell
Tutorial: Data Validation is a tool in Excel that you can use to limit what a user can enter into a...
Run a Macro when a User Does Something in the Worksheet in Excel
Tutorial: How to run a macro when a user does something in the worksheet, everything from selecting ...
Macro to add a New Line to Message Box Pop-up Windows in Excel
Macro: This is a very simple Message Box, pop-up window, macro for Excel that illustrates how to ...
Excel VBA MsgBox - Message Box Macro
Tutorial: Create a pop-up message box in Excel using VBA Macros. This allows you to show a message t...
Pass Arguments to a Macro Called from a Button or Sheet in Excel
Tutorial: How to pass arguments and values to macros called from worksheets, buttons, and anything e...



How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.


Similar Content
Pop-Up Message Box When a Range of Cells Reaches a Certain Average
Macro: This macro will display a message box when the numbers within a range of cells reaches...
Excel Data Validation - Limit What a User Can Enter into a Cell
Tutorial: Data Validation is a tool in Excel that you can use to limit what a user can enter into a...
Run a Macro when a User Does Something in the Worksheet in Excel
Tutorial: How to run a macro when a user does something in the worksheet, everything from selecting ...
Excel Forum