运行时错误91-对象变量或未设置块变量

时间:2015-05-14 00:42:27

标签: function excel-vba vba excel

print ("{0:5s} {1:7s} {2:9s} {3:6s} {4:25s} {5:s}".format('Rank', 'Points', 'Comments', 'Hours', 'Sub', 'Link'))
    for ent in results: 
        print ("{0:5s} {1:7s} {2:9s} {3:6s} {4:25s} {5:s}".format(str(ent[0]), str(ent[1]), str(ent[2]), str(round(ent[3], 2)), str(ent[4]), str(ent[5])))

嗨,谢谢你复习我的问题。我宣布了一个范围变量&用它来搜索字符串“filmtofind = searchrange.Find(what:= filmname)”&它因运行时错误而失败 运行时错误'91': 对象变量或未设置块变量 但是我可以搜索具有声明范围的相同范围 filmtofind =范围(“b2:b15”)。查找(what:= filmname)&可以找到一个变量。有人请指出错误吗?

1 个答案:

答案 0 :(得分:0)

您输入的影片不在列表中,请尝试进行错误检查:

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