How to Pop Up Message Box if Cell Value Equals “X” in Excel?


Excel is a strong programme with many capabilities to increase productivity and automate processes. Making pop-up message boxes that display personalised messages based on particular circumstances is a handy feature. In this article, we'll look at how to use Excel to construct a pop-up message box that appears when a cell value meets a specific standard, like "X". When you wish to notify users or give directions depending on specific data entered in a spreadsheet, this technique can be especially helpful. You may enhance user experience by adding an interactive component to your Excel spreadsheets by following the instructions provided in this tutorial. In order to build pop-up message boxes in Excel, let's get started.

Pop Up Message Box if Cell Value Equals “X”

Here we will add a VBA code to the sheet. So let us see a simple process to know how you can pop up a message box if the cell value equals "X" in Excel.

Step 1

Consider any Excel sheet.

First, right-click on the sheet name and select View code to open the VBA application.

Right Click > View Code.

Step 2

Then copy the below code into the text box.

Code

Private Sub Worksheet_Change(ByVal Target As Range)
   Dim xCell As Range, Rg As Range
   On Error Resume Next
   Set Rg = Application.Intersect(Target, Range("A1:C7"))
   If Not Rg Is Nothing Then
      For Each xCell In Rg
         If xCell.Value = "50" Then
            MsgBox "X Value is Used" & xCell.Address, vbInformation, "Pop Up Message"
            Exit Sub
         End If
      Next
   End If
End Sub
Private Sub Worksheet_selectionChange(ByVal Target As Range)
   Dim xCell As Range, Rg As Range
   On Error Resume Next
   Set Rg = Application.Intersect(Target, Range("A1:C7"))
   If Not Rg Is Nothing Then
      For Each xCell In Rg
         If xCell.Value = "50" Then
            MsgBox "X Value is Entred" & xCell.Address, vbInformation, "Pop Up Message"
            Exit Sub
         End If
      Next
   End If
End Sub

In the code, A1:C7 is the range of cells, and 50 is the value of X.

Step 3

Then close the VBA using Alt + Q. From now on, when any cell value is equal to 50, a pop-up message will be displayed.

This is how you can pop up a message box if the cell value equals x in Excel.

Conclusion

In this tutorial, we have used a simple example to demonstrate how you can pop up a message box if the cell value equals "X" in Excel to highlight a particular set of data.

Updated on: 07-Sep-2023

618 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements