Excel VBA“应用程序定义的或对象定义的错误”

我试图确定一个公式,该公式从D列取得数字,然后在C列中计算出这个数字减去14。然后,我将triyng自动填充到我计算的第一个单元格。

起初它工作,但现在它显示我一个错误:

应用程序定义的或对象定义的错误

到这行代码

Selection.AutoFill Destination:=ActiveCell.Range("A1:A" & lastrow) 

如果有人帮我解决这个问题,我会很高兴。

 OP_wb.Sheets("Optic Main").Activate Dim FirstRow As Range Dim lastrow As Range Set FirstRow = Range("C1").End(xlDown).Offset(1, 0) Set lastrow = Range("E1").End(xlDown).Offset(0, -2) Range("E1").End(xlDown).Offset(0, -2).Select Range(FirstRow, lastrow).FormulaR1C1 = "=(c4-14)" Selection.AutoFill Destination:=ActiveCell.Range("A1:A" & lastrow) 

在这里输入图像说明

代替

 Selection.AutoFill Destination:=ActiveCell.Range("A1:A" & lastrow) 

尝试

 Selection.AutoFill Destination:=ActiveCell.Range("A1:A" & lastrow.Row)