【问题标题】:Run time error 91-Object variable or With block variable not set运行时错误 91-对象变量或未设置块变量
【发布时间】:2015-05-14 11:41:53
【问题描述】:
Run-time error '91':

Object variable or With block variable not set

Sub findfilmnameusingeventhandler()

Sheet1.Activate

Dim searchrange As Range
Dim filmname As String
Dim releasedate As Integer
Dim filmtofind As String

Set searchrange = Range("b3", Range("b2").End(xlDown))
filmname = InputBox("Type the movie")
filmtofind = searchrange.Find(what:=filmname)

'filmtofind = Range("b2:b15").Find(what:=filmname)

MsgBox filmtofind & "  is the movie "

End Sub`

您好,感谢您查看我的问题。我已经声明了一个范围变量并使用它来搜索字符串“filmtofind = searchrange.Find(what:=filmname)”&它失败并出现运行时错误 运行时错误“91”: 未设置对象变量或 With 块变量 但是我可以使用声明的范围搜索相同的范围 filmtofind = Range("b2:b15").Find(what:=filmname) & 可以找到一个变量。有人可以指出错误吗?

【问题讨论】:

    标签: function excel vba


    【解决方案1】:

    列表中不存在您输入的电影,请尝试如下错误检查:

    Sub something()
    
    Dim searchrange As Range
    Dim filmname As String
    Dim releasedate As Integer
    Dim filmtofind As String
    
    Set searchrange = Range("B3", Range("B2").End(xlDown))
    filmname = InputBox("Type the movie")
    If WorksheetFunction.CountIf(searchrange, filmname) > 0 Then
        filmtofind = searchrange.Find(what:=filmname)
    Else
        filmtofind = "Film not found!"
    End If
    
    'filmtofind = Range("b2:b15").Find(what:=filmname)
    
    MsgBox filmtofind & "  is the movie "
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2016-10-07
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多