VBA 使用单元格 () 定义范围错误 1004



我正在寻找一个值并以此获取其行,我想用 lRow 和 2 创建一个范围变量(因为它永远是 2(,但它似乎不起作用......

Dim lCol As Long
lRow = ThisWorkbook.Sheets("Data").Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
lRow = lRow + 1
Dim newentry As Range
Set newentry = Range(Cells(lRow, 2))

在这里,lRow = 3被作为值给出...

运行时错误 1004:对象"_Global"的方法"范围"失败

如果您在范围内使用单元格,即使您只想选择 2 个单元格,也需要添加 1 个单元格:

Range(Cells(1, 1), Cells(1, 1)).Select

您的第二个单元格丢失,导致错误

最新更新