VBA to change Pivot Filter in OLAP cube to a range

前端 未结 1 1630
时光说笑
时光说笑 2020-12-20 05:31

I have a pivot table that pulls data from an OLAP cube, and I\'d like to create a macro to filter a pivot field that contains \'Week of Year\' based on the value in another

1条回答
  •  既然无缘
    2020-12-20 06:18

    It should be something like this:

    Dim aWeeks()
    Dim n                     As Long
    Dim x                     As Long
    
    n = Range("A1").Value
    
    ReDim aWeeks(n - 1)
    For x = 1 To n
        aWeeks(x - 1) = "[Time].[Week of Year].&[" & x & "]"
    Next x
    ActiveSheet.PivotTables("PivotTable3").PivotFields( _
            "[Time].[Week of Year].[Week of Year]").VisibleItemsList = aWeeks
    

    0 讨论(0)
提交回复
热议问题