gpt4 book ai didi

vba - 事件宏引发错误 "Object Required"

转载 作者:行者123 更新时间:2023-12-04 21:08:26 25 4
gpt4 key购买 nike

我有这个简单的事件宏,由于某种原因,它给我一个

Object Required



此行出错 If Not AppDate Is Nothing Then .知道可能是什么原因造成的吗?
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim LastRow As Integer
Dim ThisRow As String
Dim AppDate As Variant
Application.EnableEvents = False

LastRow = Cells(Rows.Count, "C").End(xlUp).Row
If Target.Column = 3 Then
ThisRow = Target.Row
AppDate = Target.Value
If Not AppDate Is Nothing Then
(...) Recalculate Date in Column F
Else
End If
End If

Application.EnableEvents = True
End Sub

任何建议将不胜感激。谢谢!

最佳答案

Is运算符使用对象而不是值。

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim x As Variant
Dim y As New Collection
Dim z As Object

x = Target.Value

If IsEmpty(x) Then
MsgBox "may be use this."
End If

MsgBox TypeName(x)

If y Is Nothing Then
MsgBox "Works"
End If

If z Is Nothing Then
MsgBox "Works"
End If

If x Is Nothing Then '/This won't work

End If


End Sub

关于vba - 事件宏引发错误 "Object Required",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47313257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com