我有代码获取错误424对象需要
lr = Range("O:O").Cells(Rows.Count, 1).End(xlUp).Row
For y = 0 To UBound(myVariable)
a = myVariable(y)
Range("O:O").Select
Set objXL = GetObject(, "Excel.Application")
Set z = Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
If z = "True" Then
ActiveCell.Delete shift:=xlUp
End If
MsgBox z.Value
Next
答案 0 :(得分:1)
查找检索范围对象。所以你要么:
a)激活找到的范围
Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
或强>
b)将找到的范围分配给变量
Set z = Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate 'No .Activate in here '
同时使用两者都会产生错误。
注意:强>
小心点。如果.Find
找不到匹配项,则会检索Nothing
。在这种情况下,.Activate
将弹出错误消息。所以在这里使用一些错误处理。