尝试获取End(xlDown)+ 1行时出现对象必需的错误 [英] Object required error when trying to get End(xlDown) + 1 row
本文介绍了尝试获取End(xlDown)+ 1行时出现对象必需的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码可以打开第一个工作簿,第二个工作簿,从第一个工作簿复制一个范围并将其粘贴到第二个工作簿.我想让它选择第二个工作簿中粘贴范围之后的单元格,但是它失败,并出现 Object required
Object 错误.
I have this code that opens first workbook, second workbook, copies a range from the first one and pastes it into the second one. I want to make it select the cell right after the pasted range in the second workbook, but it failes with Object required
error.
Sub tes()
'**VARIABLES**
Dim folderPath As String
folderPath = "Y:\plan_graphs\final\mich_alco_test\files\"
Dim fileTitle As String
fileTitle = "5.xlsx"
Dim dataWorkbook As Workbook
Set dataWorkbook = Application.Workbooks.Open(folderPath & fileTitle)
Dim copyRange As Range
Set copyRange = dataWorkbook.Worksheets("List1").Range("A3:F3", Range("A3").End(xlDown))
Dim resultWorkbook As Workbook
Set resultWorkbook = Application.Workbooks.Open("Y:\plan_graphs\final\mich_alco_test\result.xlsx")
copyRange.Copy
resultWorkbook.Worksheets("1").Range("A3").PasteSpecial Paste:=xlPasteFormulas
Dim nextRange As Range
Set nextRange = resultWorkbook.Worksheets("1").Range("A3:F3", _
resultWorkbook.Worksheets("1").Range("A3").End(xlDown)).Offset(1, 0).Select
End Sub
我在做什么错了?
推荐答案
您无法在同一行中设置
范围和 Select
,请尝试在代码部分下方:
You can't Set
the range and Select
it in the same line, try the code section below:
copyRange.Copy
With resultWorkbook.Worksheets("1")
.Range("A3").PasteSpecial Paste:=xlPasteFormulas
Dim nextRange As Range
Set nextRange = .Range("A3").End(xlDown).Offset(1, 0) ' set the Range first
nextRange.Select ' <-- select the Range
End With
End Sub
这篇关于尝试获取End(xlDown)+ 1行时出现对象必需的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文