只要搜索找到数据,我的案例 1 excel 宏代码就会运行,但是当搜索结果中没有任何内容时,会出现所述错误。因此,我尝试放入一个“集合”,参见案例 2……但该案例在任何搜索中都会爆炸。
案例 1:运行时错误“91”:对象变量或未设置块变量
Cells.Find(What:=sCurrentISOtext & "_", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt :=xlWhole , _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:= False, SearchFormat:=False).Activate
案例 2:运行时错误“424”:需要对象
Dim c As Range
Set c = Cells.Find(What:=sCurrentISOtext & "_", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt :=xlWhole, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:= False, SearchFormat:=False).Activate
你的意思是这样??它仍然失败。
案例 3:运行时错误“91”:对象变量或未设置块变量
Dim c As Range
c = Cells.Find(What:=sCurrentISOtext & "_", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole = 0, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase _
:=False, SearchFormat:=False)
If Not c Is Nothing Then
c.Activate
' and do something here < >
End If