我的问题是关于VBA for excel中的运行时错误91。我做了一些搜索无济于事。我的代码如下。我注意到导致错误的部分。为什么会发生这种情况,我该如何解决并继续前进?
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
答案 0 :(得分:4)
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
您需要使用“设置”关键字来指定值。
也不确定你想做什么“= isItRow =”但是你应该用两个语句来做,而不是试图像那样堆叠它们。
也没有使用aggregateRow,也没有分配类型。
答案 1 :(得分:0)
使用SET查找单元格并将其放入对象中。但是你可以让SET出来,如果你只是在行。这就是我到目前为止编写测试的方法:
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
答案 2 :(得分:0)
Sub search()
Sheets("MyShelf").Activate
Dim dd() As String
aa = Cells(Rows.Count, 1).End(xlUp).Row
ReDim dd(aa)
i = 1
Range(Cells(2, 1), Cells(aa, 1)).Select
Set bb = Selection
For Each cc In bb
dd(i) = cc.Value
i = i + 1
Next
Sheets(50).Activate
ff = 0
For i = 1 To aa - 1
ee = Range("D:D").Find(What:=dd(i), LookAt:=xlPart, LookIn:=xlValues, SearchOrder:=xlByColumns)
On Error Resume Next
If Len(ee) > 1 Then
ff = ff + 1
End If
Next
MsgBox ff
End Sub