我得到"运行时错误' 1004':应用程序定义或对象定义错误"当命中Run Sub(F5)时运行整个子程序。但是,当我使用调试功能(F8)逐步执行它时,它会无误地传递此行。有什么我可以在代码中更改以纠正此问题。代码如下:
lastrow = Sheet9.Cells(Rows.count, 1).End(xlUp).Row
Range(Sheet9.Cells(1, 1), Sheet9.Cells(lastrow, 14)).Clear
lastrow = Sheet3.Cells(Rows.count, ProjCol).End(xlUp).Row
For i = 1 To lastrow
Sheet3.Range(Sheet3.Cells(i + 1, ProjCol), Sheet3.Cells(i + 1, LampCol)).Copy Destination:=Sheet9.Range(Sheet9.Cells(i, 1), Sheet9.Cells(i, 2))
Next i
lastrow2 = Sheet9.Cells(Rows.count, 1).End(xlUp).Row
'ERROR OCCURS WITH LINE BELOW
Sheet9.Range(Cells(1, 1), Cells(lastrow2, 2)).RemoveDuplicates Columns:=Array(1, 2), Header:=xlNo