VBA 选择数据透视表 [英] VBA Select Pivot Table
问题描述
我正在尝试使用 VBA 选择数据透视表,但遇到了一个问题,即数据透视表可能从 A3(如果没有激活报告过滤器)或 A6(如果选择了 3 个报告过滤器)等开始.因此,数据透视表不会始终位于工作表上的同一点上.清除数据透视表只会删除所有数据和报告过滤器,但不会将数据透视表移回其原始位置.有没有办法使用 VBA 来选择数据透视表(以便能够将数据复制并粘贴到新的工作表中),而不管它在工作表上的位置?
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?
谢谢.
更新 - 我已经想出了如何做到这一点.真的很简单:
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
推荐答案
使用以下代码(为数据透视表名称 PivotTable1 提供):
Use the following code (given for a pivot table names PivotTable1):
Dim PT As PivotTable
Set PT = ActiveSheet.PivotTables(1)
PT.TableRange1.Select
这篇关于VBA 选择数据透视表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!