【问题标题】:Getting Runtime Error 91获取运行时错误 91
【发布时间】:2016-02-12 01:20:16
【问题描述】:

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

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

【问题讨论】:

  • Cells.Find(What:="0", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _ xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _ , SearchFormat:=False).Activate THIS IS THE CODE IN QUESTION
  • 另外,一个快速的解决方案可能只是删除最后的.Activate。但是请提供更多代码,因为我不知道您如何使用Cells.Find()

标签: excel runtime


【解决方案1】:

你可以做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去掉。您想要单元格范围,而不是激活它。

【讨论】:

    猜你喜欢
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-25
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多