获取运行时错误91

时间:2016-02-11 16:45:45

标签: excel runtime

我在循环中找到了这个。当有一个" 0"它可以正常工作。但是当没有更多" 0"我得到运行时错误91.有什么想法吗?

Cells.Find(What:="0", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
  xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
  , SearchFormat:=False).Activate

1 个答案:

答案 0 :(得分:0)

你可以this

Dim rngFound As Range

Set rngFound = Sheets("WhateverSheet").Cells.Find(What:="0", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

If Not rngFound Is Nothing Then
  'you found the value - do whatever
Else
  ' you didn't find the value
End if

啊,或者最后取出.Activate。您需要单元格范围,而不是激活它。