VBA 选择数据透视表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18383894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Select Pivot Table
提问by Nat Aes
I am trying to select a pivot table using VBA, and have encountered an issue in that the pivot table may start at A3 (if there are no report filters activated) or A6 (if 3 report filters have been chosen) etc. Accordingly the pivot table will not always be on the same point on the worksheet. Clearing the pivot only removes all the data and report filters, although does not move the pivot table back up to its original position. Is there any way to use VBA to select the pivot table (so as to be able to copy and paste the data into a new worksheet) regardless of where it may be positioned on the worksheet?
我正在尝试使用 VBA 选择数据透视表,但遇到了一个问题,即数据透视表可能从 A3(如果没有激活报告过滤器)或 A6(如果选择了 3 个报告过滤器)等开始。因此,数据透视表表格并不总是在工作表上的同一点上。清除数据透视表只会删除所有数据和报告过滤器,但不会将数据透视表移回其原始位置。有没有办法使用 VBA 来选择数据透视表(以便能够将数据复制并粘贴到新的工作表中),而不管它在工作表上的位置?
Thanks.
谢谢。
UPDATE - I have since figured out how to do this. Its quite simple really:
更新 - 我已经想出了如何做到这一点。它真的很简单:
Dim PT As PivotTable
Set PT = ActiveSheet.PivotTables(1)
PT.TableRange1.Select
回答by Nat Aes
Use the following code (given for a pivot table names PivotTable1):
使用以下代码(为数据透视表名称 PivotTable1 提供):
Dim PT As PivotTable
Set PT = ActiveSheet.PivotTables(1)
PT.TableRange1.Select