[英]Copy PivotTable range from one worksheet to another worksheet. Code is copying active sheet data instead
I have a PivotTable on worksheet (inventorySheet) and I want to copy the PivotTable data, which starts on cells P5 and Q5.我在工作表 (inventorySheet) 上有一个数据透视表,我想复制从单元格 P5 和 Q5 开始的数据透视表数据。 I have a macro button I press on another worksheet (the sheet i want the data to be pasted on), but my code is copying data from the active worksheet instead of from inventorySheet.
我在另一个工作表(我想要粘贴数据的工作表)上按下了一个宏按钮,但我的代码是从活动工作表而不是从inventorySheet 复制数据。
I'm new to coding, but shouldn't my code Range("P5:Q5", Range("P5:Q5").End(xlDown)).Copy copy data from inventorySheet since it's within the With statement?我是编码新手,但我的代码不应该是 Range("P5:Q5", Range("P5:Q5").End(xlDown)).Copy copy copy data from inventorySheet 因为它在 With 语句中?
With inventorySheet
.PivotTables("inventoryPivot").ClearAllFilters
.PivotTables("inventoryPivot").PivotFields("Type"). _
CurrentPage = "REGIONAL"
Range("P5:Q5", Range("P5:Q5").End(xlDown)).Copy
End With
Thanks!谢谢!
Something like this:像这样的东西:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.