VBA在查找函数运行时错误91

我的问题是有关Excel中的VBA运行时错误91。 我做了一些search无济于事。 我的代码如下。 我注意到导致错误的部分。 为什么会发生这种情况,我该如何解决这个问题,并继续前进?

Sub RemoveFooterRows(theFile) Dim found As Range Dim aggregateRow ''Error is from section below found = isItRow = Workbooks(theFile).Worksheets(1).Columns(1).Find _ ("Summary", Range("A1"), xlValues, xlPart, xlByRows, xlNext, False, , False) ''Error is from section above MsgBox ("val is " & found.Row) End Sub 

 Sub RemoveFooterRows(theFile) Dim found As Range Set found = Workbooks(theFile).Worksheets(1).Columns(1).Find _ ("Summary", Range("A1"), xlValues, xlPart, xlByRows, xlNext, False, , False) MsgBox ("val is " & found.Row) End Sub 

您需要使用“Set”关键字来分配值。

也不知道你想要什么“= isItRow =”做,但你应该做两个声明,而不是像这样堆叠它们。

此外,还没有使用aggregateRow,也没有分配types。

您使用SET来查找单元格并将其放入一个对象中。 但是如果你只是在行中,你可以让SET出来。 这就是我迄今为止要写这个testing的方法:

 Dim Rw As Long On Error Resume Next Rw = Workbooks(theFile).Worksheets(1).Columns(1).Find _ ("Summary", LookIn:=xlValues, LookAt:=xlPart).Row If Rw > 0 Then MsgBox "The row is " & Rw Else MsgBox "Not found" End If