【问题标题】:How can i fix the run-time error '91' in excel VBA?如何修复 excel VBA 中的运行时错误“91”?
【发布时间】:2021-12-27 12:26:52
【问题描述】:

我试图触发第 q 列的弹出消息,如果它与“打开”或“关闭”不同,表示请输入理由此代码运行良好,但如果我点击不同的列,它会给我下面的错误消息(其他比Q)

我怎样才能摆脱这条消息?

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not (Application.Intersect(Range("Q2:Q3977"), Target) = "Open") And Not (Application.Intersect(Range("Q2:Q3977"), Target) = "Closed") Then
        MsgBox "Please Enter Justification"
    
    End If
End Sub

【问题讨论】:

    标签: excel vba msgbox


    【解决方案1】:

    一种方法是只检查Target.Column 以确保它首先是Q

    Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Column = 17 Then
        If Not (Application.Intersect(Range("Q2:Q3977"), Target) = "Open") And Not (Application.Intersect(Range("Q2:Q3977"), Target) = "Closed") Then
            MsgBox "Please Enter Justification"
        
        End If
      End If
    End Sub
    

    可能有更酷的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多