跳到主要內容

如果在Excel中單元格值等於“ X”,如何彈出消息框?

查找指定範圍內的某些內容時,彈出消息框會很有幫助。 例如,您在範圍A50:C1中找到等於7的單元格值,並且需要彈出一個消息框來告訴您該單元格值是否存在。 以下兩種方法可以為您提供幫助。

如果單元格值等於VBA代碼的“ X”,則彈出消息框
使用Kutools for Excel,如果單元格值等於``X'',則輕鬆彈出消息框


如果單元格值等於VBA代碼的“ X”,則彈出消息框

當特定值存在於指定範圍內時,以下VBA代碼可以幫助創建彈出消息框。 請執行以下操作。

1.在工作表中,您需要檢查指定範圍內的值,右鍵單擊工作表選項卡欄中的選項卡名稱,然後單擊 查看代碼 從右鍵單擊菜單中。 看截圖:

doc消息框(如果單元格值為1)

2。 在裡面 Microsoft Visual Basic for Applications 窗口,將以下VBA代碼複製並粘貼到“代碼”窗口中。

VBA代碼:如果單元格值等於“ 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。 按 其他 + Q 同時關閉按鍵 Microsoft Visual Basic for Applications 窗口,然後返回工作表。

從現在開始,當單元格值在A1:C7範圍內更改並且單元格值等於“ 50”時,您將得到一個消息框,如下圖所示。

此外,如果單元格值存在,則只需選擇範圍即可彈出消息框。

doc消息框(如果單元格值為1)

筆記:

1.如果單元格值不符合條件,則不會彈出消息框。
2.在上面的代碼中,您可以根據需要更改單元格引用和值。
3.當有多個結果時,它只能顯示一個匹配的單元格引用。

如果用Kutools for Excel單元格值等於“ X”,則彈出消息框

選擇特定的單元格 的效用 Excel的Kutools 也可以幫助您解決此問題。 請執行以下操作。

申請前 Excel的Kutools首先下載並安裝.

1.選擇要查找是否存在單元格值的範圍,然後單擊 庫工具 > 選擇 > 選擇特定的單元格

2。 在裡面 選擇特定的單元格 對話框中,選擇 細胞 在選項 選擇類型 部分,然後選擇 等於 在第一 特定類型 下拉列表,然後在下一個文本框中鍵入單元格的值,最後單擊 OK 按鈕。

doc消息框(如果單元格值為1)

如果單元格值存在於指定範圍內,則將顯示以下消息框,單擊 OK 按鈕,將選中該單元格。

doc消息框(如果單元格值為1)

否則,您將得到如下所示的消息框,如屏幕截圖所示。

doc消息框(如果單元格值為1)

  如果您想免費試用(30天)此實用程序, 請點擊下載,然後按照上述步驟進行操作。


使用Kutools for Excel,如果單元格值等於``X'',則輕鬆彈出消息框


相關文章:

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
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