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.
Excel Productivity Tools
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 70% of your time and solve 80% Excel problems for you. 300+ advanced features designed for 1500+ work scenario, make Excel much easy and increase productivity immediately. 60-day Unlimited Free Trial
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:
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.
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.
The Select Specific Cells utility of Kutools for Excel can also help you to solve this problem. Please do as follows.
1. Select the range you want to find if cell value existing in, then click Kutools > Select > Select Specific Cells. See screenshot:
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.
If the cell value exists in specified range, you will get the following message box, click the OK button, the cell will be selected.
Otherwise, you will get the message box as below screenshot shown.
Kutools for Excel includes more than 300 handy Excel tools. Free to try with no limitation in 60 days. Download the free trial now!
- How to delete entire row if cell contains zero in Excel?
- How to count cells with specific text in selection in Excel?
Excel Productivity Tools
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 1 years agoIs there a way to update for 2 values in the same range? ex "50" or "100" ?
To post as a guest, your comment is unpublished.· 1 years agoThis 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
To post as a guest, your comment is unpublished.· 1 years agoDear 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!