格式化单元格会阻止我粘贴范围

For i = 3 To numPer + 3 Sheets("Key Assumptions Generated").Select Cells(2, i).PasteSpecial Cells(1, i).Value = l Set curCell = Worksheets("Key Assumptions Generated").Cells(2, i) Cells(1, i).NumberFormat = "@" l = l + 1 Next i 

这是我的系。 当我删除'Cells(1,i).NumberFormat =“@”'代码运行正常。 但是,当我尝试格式化循环将停止运行,我会得到一个错误与类的PasteSpecial方法。

是的,正如你已经发现调整一个单元格的数字格式的行为将取消以前的“跳舞ant”的复制操作。 你不能粘贴没有被复制的东西(即驻留在剪贴板上)。

尽pipe一举三得(无论如何都是这样快)。

 with workSheets("Key Assumptions Generated") .Cells(2, 3).resize(1, numper).PasteSpecial .Cells(2, 3).resize(1, numper).NumberFormat = "@" .Cells(2, 3).offset(-1, 0) = l .Cells(2, 3).resize(1, numper).offset(-1, 0).DataSeries Rowcol:=xlRows, Type:=xlLinear, Step :=1 end with