【发布时间】:2026-01-05 01:00:01
【问题描述】:
我有一个 Excel 宏,它已经运行了一年多,直到昨天我收到一个错误 Run-time error '91'. Object variable or With block variable not set。我可以确认所有工作表都存在。感谢任何解决问题的建议。我已经突出显示了发生错误的行。
Sub Insert_Last_to_Input()
Dim dateBaltic As Date
Dim rngFFA As Range
Dim longLastRowNo As Long
Dim longBaltic, longFEI, longMB As Long
dateBaltic = Sheets("Input").Range("B2").Value
Sheets("Baltic FFA").Select
With ActiveSheet
longLastRowNo = .Range("A:A").Find(What:=dateBaltic, LookIn:=xlValues).Row
'**Error above:"Run-time error '91'. Object variable or With block variable not set"**
Set rngFFA = .Range("B" & longLastRowNo & ":F" & longLastRowNo)
End With
End Sub
【问题讨论】:
-
你需要检查
.Find是否返回了一些东西。 Here 就是一个例子。查看该链接中的 第 1 节If Not aCell Is Nothing Then顺便说一句,此类问题在 * 中已被问过无数次。 -
在一行中声明多个变量,例如输入
Long是这样完成的:Dim longBaltic As Long, longFEI As Long, longMB As Long。在您的代码中,前两个声明为Variant。
标签: excel vba excel-2010