【发布时间】:2014-07-09 20:28:41
【问题描述】:
我遇到了一个新的 VBA 问题:某些代码行仅在相关工作表处于活动状态时才会执行,否则它们会生成错误(运行时错误“1004”:应用程序定义或对象定义错误")。我需要代码能够在后台运行。
也许有一双新的(VBA 精通)眼睛的人可以发现这些线条有什么问题。 (我在这里将它们一起发布,但它们实际上来自不同的宏。)
Dim senaste As Range
Sheets("PA").Range(Cells(senaste.Row, (senaste.Column - 2)), Cells(senaste.Row, senaste.Column)).Copy
Worksheets("GL").Range(Cells(3, 1), Cells(Sheets("GL").UsedRange.Rows.Count, Sheets("GL").UsedRange.Columns.Count)).Delete
编辑:下面的答案很好!用不同的线做同样的事情,坐标变得疯狂,发生了什么? (-4 和 -9 曾经是 -1。)
Set pt = Worksheets("PA").PivotTables("A")
pt.DataBodyRange.Range(pt.DataBodyRange.Cells(-4, (pt.DataBodyRange.Cells.Columns.Count - 9)), pt.DataBodyRange.Cells((pt.DataBodyRange.Cells.Rows.Count - 6), (pt.DataBodyRange.Cells.Columns.Count - 7))).Copy
【问题讨论】: