我正在运行代码将名称从一个工作簿粘贴到另一个工作簿并自动填充,但在运行代码时我得到运行时错误9,这是示例代码
Sub test()
Dim WB As Workbook
Dim lstRow As long
workbook.open("path")
Set WB = activeworkbook
lstRow = Range("M2").End(xlDown).Row
ThisWorkbook.Activate
Worksheets("Sheet1").Range("G3").Copy
WB3.Sheets(("I2:I") & lstRow).PasteSpecial xlpastevalue
End Sub
答案 0 :(得分:0)
OPTION EXPLICIT
Sub test()
Dim WB As Workbook
Set WB = workbook.open("path")
with WB.WorkSheets("Sheet1")
With .Range(.Cells(2, "M"), .Cells(.rows.count, "M").End(xlup))
.Offset(1, -6).Resize(.Rows.Count -1, 1) = ThisWorkbook.Worksheets("Sheet1").Range("G3").Value
End With
End With
End Sub