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

问题描述:

我想确定一个公式,该公式需要从列D中取出数字,并计算出C列中的数字减去14. 然后,我要自动填充范围到我计算的第一个单元格。Excel VBA“应用程序定义的或对象定义的错误”

首先是工作,但现在它显示我的错误:

appliction-defined or object-defined error

这行代码

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

如果有人能帮助我解决这个prblem我会高兴。

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) 

enter image description here

而不是

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

尝试

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

感谢它的工作 –