【发布时间】:2017-11-18 04:50:52
【问题描述】:
我正在运行下面的 VBA 代码 -
lastColumn = Cells(5, Columns.count).End(xlToLeft).Column
count_dates = Range("H2").Value
Set cellSource = Range(Cells(6, 13).Address)
Set cellTarget = Range(Cells(6, 13), Cells(count_dates + 5, lastColumn))
cellSource.AutoFill Destination:=cellTarget, Type:=xlFillDefault
代码在一台 PC (Excel 2016) 上运行良好,但在另一台 PC (Excel 2010) 上无法运行。我无法弄清楚同样的原因。
单元格 (6,13) 有一个公式,我想水平向右和垂直向下拖动
我得到的错误是 - 错误 1004:范围类的自动填充方法失败
【问题讨论】:
-
你基本上是在做 Range(Cells(6, 13), Cells(count_dates + 5, lastColumn)) = Range(Cells(6, 13)) 吗?如果是这样,只需重新编写以避免自动填充。
-
Range(Cells(6, 13).Address)与Cells(6, 13)完全相同...您正在做的是计算cells(6,13)范围的地址,然后您指的是该地址的范围。 .... 有点像i want to go to the house that is at the address of the house where Richard lives而不是i want to go to Richard's house -
您应该告诉我们自动填充单元格中有哪些数据,以便我们重现。
-
@Akshat Agrawal
LastColumn和Count_Dates的价值是什么 -
已编辑问题以使其更清晰并消除歧义