+ Reply to Thread
Results 1 to 8 of 8

OLAP Pivot Filter using VBA

  1. #1
    Registered User
    Join Date
    11-06-2008
    Location
    Gorton
    Posts
    14

    OLAP Pivot Filter using VBA

    Hi,

    Probably a really obvious answer but I’m wondering if anyone can please assist. I have a OLAP Pivot table and need a Macro which only selects certain items, so far I have the below. I can get it to hide all the years which is all items but then I want it to only select the dates between 08/06/2014 – 12/06/2014. For some reason it doesn’t like the VisibleItemsList bit, what am I doing wrong? Eventually I want the dates that need to be taken from cells which someone inputs but for now I’m happy just to get it to filter by pre-determined dates in the code.

    Sub PivotFilter()
    ActiveSheet.PivotTables("PivotTable2").PivotFields( _
    "[Dates].[PeriodDates].[PeriodYear]").HiddenItemsList = Array( _
    "[Dates].[PeriodDates].[PeriodYear].&[2011]", _
    "[Dates].[PeriodDates].[PeriodYear].&[2012]", _
    "[Dates].[PeriodDates].[PeriodYear].&[2013]", _
    "[Dates].[PeriodDates].[PeriodYear].&[2014]")

    ActiveSheet.PivotTables("PivotTable2").PivotFields( _
    "[Dates].[PeriodDates].[Day]").VisibleItemsList = Array( _
    "[Dates].[PeriodDates].[Day].&[2014-06-08T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2014-06-09T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2014-06-10T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2014-06-11T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2014-06-12T00:00:00]")
    End Sub

    Thanks

    Tom

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: OLAP Pivot Filter using VBA

    Perhaps you do not wish to hide 2014 in PeriodYear?
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  3. #3
    Registered User
    Join Date
    11-06-2008
    Location
    Gorton
    Posts
    14

    Unhappy Re: OLAP Pivot Filter using VBA

    Thanks for the reply Izandol.

    I've tried not hiding 2014 but it's still crashing when it get to this bit:

    ActiveSheet.PivotTables("PivotTable2").PivotFields( _
    "[Dates].[PeriodDates].[Day]").VisibleItemsList = Array( _
    "[Dates].[PeriodDates].[Day].&[2014-06-08T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2014-06-09T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2014-06-10T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2014-06-11T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2014-06-12T00:00:00]")

    I can get it to hide ever date apart from the ones I need but that means I have to define each date individually apart from the ones I need filtered. It’s really bugging me that if I can do that why can’t I just ask it to make them visible and define only the items I needI can get it to hide ever date apart from the ones I need but that means I have to define each date individually apart from the ones I need filtered. It’s really bugging me that if I can do that why can’t I just ask it to make them visible and define only the items I need.

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: OLAP Pivot Filter using VBA

    If you record macro while selecting some dates from Day field, what code is provided?

  5. #5
    Registered User
    Join Date
    11-06-2008
    Location
    Gorton
    Posts
    14

    Re: OLAP Pivot Filter using VBA

    I recorded a macro where I just select one day to see what it gives me and it's doing it the long\awkward way of asking for everything to be hidden but the item/date I have selected! The below code is simply me clicking on the filter and ticking one day.

    ActiveSheet.PivotTables("PivotTable2").CubeFields(2).TreeviewControl.Drilled = _
    Array(Array(""), Array("[Dates].[PeriodDates].[PeriodYear].&[2013]"), Array( _
    "[Dates].[PeriodDates].[PeriodNo].&[255]"), Array( _
    "[Dates].[PeriodDates].[PeriodWeek].&[2551]"))
    ActiveSheet.PivotTables("PivotTable2").PivotFields( _
    "[Dates].[PeriodDates].[PeriodYear]").HiddenItemsList = Array( _
    "[Dates].[PeriodDates].[PeriodYear].&[2011]", _
    "[Dates].[PeriodDates].[PeriodYear].&[2012]")
    ActiveSheet.PivotTables("PivotTable2").PivotFields( _
    "[Dates].[PeriodDates].[PeriodNo]").HiddenItemsList = Array( _
    "[Dates].[PeriodDates].[PeriodNo].&[253]", _
    "[Dates].[PeriodDates].[PeriodNo].&[254]", _
    "[Dates].[PeriodDates].[PeriodNo].&[256]", _
    "[Dates].[PeriodDates].[PeriodNo].&[257]", _
    "[Dates].[PeriodDates].[PeriodNo].&[258]", _
    "[Dates].[PeriodDates].[PeriodNo].&[259]", _
    "[Dates].[PeriodDates].[PeriodNo].&[260]", _
    "[Dates].[PeriodDates].[PeriodNo].&[261]", _
    "[Dates].[PeriodDates].[PeriodNo].&[262]", _
    "[Dates].[PeriodDates].[PeriodNo].&[263]", _
    "[Dates].[PeriodDates].[PeriodNo].&[264]")
    ActiveSheet.PivotTables("PivotTable2").PivotFields( _
    "[Dates].[PeriodDates].[PeriodWeek]").HiddenItemsList = Array( _
    "[Dates].[PeriodDates].[PeriodWeek].&[2552]", _
    "[Dates].[PeriodDates].[PeriodWeek].&[2553]", _
    "[Dates].[PeriodDates].[PeriodWeek].&[2554]", _
    "[Dates].[PeriodDates].[PeriodWeek].&[2555]")
    ActiveSheet.PivotTables("PivotTable2").PivotFields( _
    "[Dates].[PeriodDates].[Day]").HiddenItemsList = Array( _
    "[Dates].[PeriodDates].[Day].&[2013-02-24T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2013-02-26T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2013-02-27T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2013-02-28T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2013-03-01T00:00:00]", _
    "[Dates].[PeriodDates].[Day].&[2013-03-02T00:00:00]")

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: OLAP Pivot Filter using VBA

    What happens if you clear all filters from the pivot table and then only run this code:
    Please Login or Register  to view this content.
    Is it still the same error?

  7. #7
    Registered User
    Join Date
    11-06-2008
    Location
    Gorton
    Posts
    14

    Re: OLAP Pivot Filter using VBA

    It crashes out with the below message messages

    Untitled.png

  8. #8
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: OLAP Pivot Filter using VBA

    Did you remove this field from the pivot table or only clear the filters? This is same field reference as macro code used.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. OLAP Pivot Table filter with VBA macro
    By AmateurPro in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-25-2014, 09:34 AM
  2. Filter multiple pivot tables based on same cell value (OLAP based)
    By natsuki-hime in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2012, 05:21 AM
  3. Setting (OLAP) pivot filter from VBA
    By DavidBytheway in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2011, 10:07 AM
  4. Excel 2007 : OLAP pivot table automatic filter
    By serverdar in forum Excel General
    Replies: 0
    Last Post: 06-03-2011, 04:30 AM
  5. [SOLVED] OLAP Pivot Filter from array
    By Sharon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-15-2006, 10:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1