跳到主要内容

如果在Excel中单元格值等于“ X”,如何弹出消息框?

查找指定范围内的某些内容时,弹出消息框会很有帮助。 例如,您在范围A50:C1中找到等于7的单元格值,并且需要弹出一个消息框来告诉您该单元格值是否存在。 以下两种方法可以为您提供帮助。

如果单元格值等于VBA代码的“ X”,则弹出消息框
如果单元格值等于“X”,使用 Kutools for Excel 轻松弹出消息框


如果单元格值等于VBA代码的“ X”,则弹出消息框

当特定值存在于指定范围内时,以下VBA代码可帮助创建弹出消息框。 请执行以下操作。

1.在工作表中,您需要检查指定范围内的值,右键单击工作表选项卡栏中的选项卡名称,然后单击 查看代码 从右键单击菜单中。 看截图:

doc消息框(如果单元格值为1)

2.在 Microsoft Visual Basic应用程序 窗口,将以下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应用程序 窗口,然后返回工作表。

从现在开始,当单元格值在A1:C7范围内更改并且单元格值等于“ 50”时,您将得到一个消息框,如下图所示。

此外,如果单元格值存在,则只需选择范围即可弹出消息框。

doc消息框(如果单元格值为1)

:

1.如果单元格值不符合条件,则不会弹出消息框。
2.在上面的代码中,您可以根据需要更改单元格引用和值。
3.当有多个结果时,它只能显示一个匹配的单元格引用。

如果单元格值等于“X”,则弹出消息框 Kutools for Excel

选择特定的单元格 实用程序 Kutools for Excel 也可以帮助您解决此问题。 请执行以下操作。

申请前 Kutools for Excel首先下载并安装.

1.选择要查找是否存在单元格值的范围,然后单击 库工具 > 选择 > 选择特定的单元格

2.在 选择特定的单元格 对话框中,选择 手机 在选项 选择类型 部分,然后选择 等于 在第一个 特定类型 下拉列表,然后在下一个文本框中键入单元格的值,最后单击 OK 按钮。

doc消息框(如果单元格值为1)

如果单元格值存在于指定范围内,您将收到以下消息框,单击 OK 按钮,将选中该单元格。

doc消息框(如果单元格值为1)

否则,您将得到如下所示的消息框,如屏幕截图所示。

doc消息框(如果单元格值为1)

  如果您想免费试用(30天)此实用程序, 请点击下载,然后按照上述步骤进行操作。


如果单元格值等于“X”,使用 Kutools for Excel 轻松弹出消息框


相关文章:

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 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