【问题标题】:VBA PivotItems Index VariableVBA PivotItems 索引变量
【发布时间】:2013-10-10 17:10:49
【问题描述】:

我正在尝试遍历 OLAP 数据透视表中不同年份的数据,并且对于每一年我都必须向下钻取以获取我正在寻找的数据。这是宏记录器给我的 2013 年:

'This is the cell that has to be drilled down
Range("A2").Select

With ActiveSheet.PivotTables("PivotTable1").PivotFields("[Date].[YMD].[Year Name]") _

.PivotItems("[Date].[YMD].[Year Name].&[***2013***]").DrilledDown = True

End With

[Date].[YMD] 是字段名称,[Year Name] 是源名称。

但是,我试图用变量“Yr”替换 &[2013],这将允许我选择并深入了解每一年。

但我收到以下消息:“无法获取 PivotField 类的 PivotItems 属性”

PivotItems 索引是否有特定的语法?使用变量从 OLAP 数据透视表中引用是否有限制?我尝试将 Yr 定义为 Double 和 Variable,但没有帮助..

感谢您的建议!

【问题讨论】:

  • 为什么你有一个额外的“_”在那里?这基本上是 VBA 中的“在下一行继续此命令”语法 - 尝试删除它的代码。现在你的 with 没有意义。

标签: vba variables indexing pivot-table


【解决方案1】:

试试这个

Dim YR As Integer

YR = 2013

With ActiveSheet.PivotTables("PivotTable1").PivotFields("[Date].[YMD].[Year Name]") _
.PivotItems("[Date].[YMD].[Year Name].&[" & YR & "]").DrilledDown = True


End With

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    • 2013-01-27
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    相关资源
    最近更新 更多