首页 > 解决方案 > MS excel VBA:消息框依赖于 Vlookup 结果

问题描述

我正在努力寻找正确的代码位,以便根据日期表在 Excel 中弹出一个消息框。我的工作簿包含一个用户选择自由选择日期范围的首页,如果任何日期对应于我的日期表中的日期,我需要我的工作簿弹出一条消息(我附上了一些屏幕截图以创建清晰的图片.

创建弹出框等任务。我非常满意,但是如果所选日期之间的任何日期记录了事件,我真的找不到只显示消息框的方法。

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range

Application.EnableEvents = True

' The variable KeyCells contains the cells that will
    ' cause an alert when they are changed.
    Set KeyCells = Range("D6")

If Not Application.Intersect(KeyCells, Target.Range("A1:G25")) _
           Is Nothing Then
                 Call EventFinder
End If
End Sub

结果

在此处输入图像描述

标签: excelvba

解决方案


    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range

Application.EnableEvents = True

' The variable KeyCells contains the cells that will
    ' cause an alert when they are changed.
    Set KeyCells = Range("E6")

If Not Application.Intersect(KeyCells, Target.Range("A1:G25")) _
           Is Nothing Then
                 'Call Any Macro You Want
End If
End Sub

使用此代码,我可以在工作表中的单元格 E6 发生更改时启动宏!请注意,此代码需要插入到工作簿对象中!没有进入一个模块。可以将要调用的宏插入到模块中。


推荐阅读