Skip to main content

How to pop up message box if cell value equals “X” in Excel?

Popping up message box helps a lot while finding certain content in specified range. For example, you are finding cell value which equals 50 in a range A1:C7, and you need a message box popping up to tell you whether the cell value exist or not. The following two methods can help you.

Pop up message box if cell value equals “X” with VBA code
Easily pop up message box if cell value equals “X” with Kutools for Excel


Pop up message box if cell value equals “X” with VBA code

The following VBA code can help to create a pop up message box when the certain value exists in specified range. Please do as follows.

1. In the worksheet you need to check values in specified range, right click the tab name in the sheet tab bar, and then click View Code from the right-clicking menu. See screenshot:

doc message box if cell value 1

2. In the Microsoft Visual Basic for Applications window, copy and paste the following VBA code into the Code window.

VBA code: pop up message box if cell value equals “X”

Private Sub Worksheet_Change(ByVal Target As Range)
'Update: 2017/7/25
    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 "guest entered into cell " & xCell.Address, vbInformation, "Kutools for Excel"
                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 "guest entered into cell " & xCell.Address, vbInformation, "Kutools for Excel"
                Exit Sub
            End If
        Next
    End If
End Sub

3. Press Alt + Q keys simultaneously to close the Microsoft Visual Basic for Applications window and go back to the worksheet.

From now on, when cell values are changed in range A1:C7 and there is cell value equals “50”, you will get a message box as below screenshot shown.

Besides, you can just select the range to pop up the message box if the cell value exists.

doc message box if cell value 1

Notes:

1. If the cell value does not meet the criteria, the message box won’t pop up.
2. In the above code, you can change the cell reference and value to your need.
3. It only can display one matching cell reference when there are multiple results.

Pop up message box if cell value equals “X” with Kutools for Excel

The Select Specific Cells utility of Kutools for Excel can also help you to solve this problem. Please do as follows.

Before applying Kutools for Excel, please download and install it firstly.

1. Select the range you want to find if cell value existing in, then click Kutools > Select > Select Specific Cells

2. In the Select Specific Cells dialog box, select the Cell option in the Selection type section, then select Equals in the first Specific type drop-down list and type the cell value in the next text box, and finally click the OK button.

doc message box if cell value 1

If the cell value exists in specified range, you will get the following message box, click the OK button, the cell will be selected.

doc message box if cell value 1

Otherwise, you will get the message box as below screenshot shown.

doc message box if cell value 1

  If you want to have a free trial (30-day) of this utility, please click to download it, and then go to apply the operation according above steps.


Easily pop up message box if cell value equals “X” with Kutools for Excel


Related articles:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Is there a way to update for 2 values in the same range? ex "50" or "100" ?
This comment was minimized by the moderator on the site
Hi Rajesh,
The below code can help you solve the problem, please have a try. Thank you!

Private Sub Worksheet_Change(ByVal Target As Range)

'Update: 2020/8/21

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" Or xCell.Value = "100" Then

MsgBox "guest entered into cell " & xCell.Address, vbInformation, "Kutools for Excel"

Exit Sub

End If

Next

End If

End Sub
This comment was minimized by the moderator on the site
Hi Crystal, Both conditions are working . Thank you so much ThanksRajesh
This comment was minimized by the moderator on the site
Is there a way to update for 2 values in the same range? ex "50" or "100" ?
This comment was minimized by the moderator on the site
I also tried duplicating this code, and changing to a different range where my data is repeated, but it appears the "Worksheet - Change" function can only be used once. Is this true?
This comment was minimized by the moderator on the site
This script works fine when the cell was enter manually. But when I try to copy the whole line from the other line and paste it to the new line, the pop up window will still come up even the cell on the new line didn't contain the key word. Any way to get rid of it? Please advice. Thanks
This comment was minimized by the moderator on the site
Dear TANGO, Thank you for your comment! We have updated the VBA script to get rid of the problem you mentioned above. Hope the new code can ease your work. If you have any problem, please do hesitate to contact us! Thanks again for your comment!
This comment was minimized by the moderator on the site
please need your help give me your email address Linda mine is
This comment was minimized by the moderator on the site
Hi,
Sorry for replying so late. Please contact me at .
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations