我有一个工作表上的PivotTable (inventorySheet),我想复制从单元格P5和Q5开始的PivotTable数据。我在另一个工作表(我希望将数据粘贴到的工作表)上按下一个宏按钮,但我的代码是从活动工作表而不是从inventorySheet复制数据。
我是编程新手,但是我的代码范围(“p5:q5”,Range("P5:Q5").End(xlDown)).Copy是否应该从inventorySheet复制数据,因为它在With语句中?
With inventorySheet
.PivotTables("inventoryPivot").ClearAllFilters
.PivotTables("inventoryPivot").PivotFields("Type"). _
CurrentPage = "REGIONAL"
Range("P5:Q5", Range("P5:Q5").End(xlDown)).Copy
End With
谢谢!
发布于 2021-03-26 20:40:08
如下所示:
Dim rngCopy As range
With inventorySheet.PivotTables("inventoryPivot")
.ClearAllFilters
.PivotFields("Type").CurrentPage = "REGIONAL"
'data body range plus one column to the left...
With .DataBodyRange
Set rngCopy = .Offset(0, -1).Resize( , .Columns.Count +1)
End with
rngCopy.Copy
End With
https://stackoverflow.com/questions/66822976
复制