如何修复 excel VBA 中的 运行 时间错误“91”?

How can i fix the run-time error '91' in excel VBA?

如果 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

一种方法是先检查 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

可能还有更酷的方法。