【发布时间】:2018-09-27 09:37:05
【问题描述】:
只要搜索找到数据,我的案例 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
【问题讨论】:
-
你的意思是这样的??它仍然失败。案例 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 ' 并在此处执行操作 End If
-
tldr: 如果在此期间重新定义 Find 操作,则无法 FindNext。
-
如果您坚持混淆您的问题,那么 cmets 将不再是 20 个问题的游戏。 edit您的问题包括这些说明。