+ Reply to Thread
Results 1 to 7 of 7

Set the value of a Pivot Table Page Filter based on the calendar day

  1. #1
    Registered User
    Join Date
    03-06-2015
    Location
    Dallas, Texas
    MS-Off Ver
    2010
    Posts
    4

    Set the value of a Pivot Table Page Filter based on the calendar day

    I recorded a macro to set the value of a Pivot Table Page Filter. I copied that macro code to an existing function that refreshes all pivot tables in the workbook. When I run the code in Excel, it works perfectly. When I invoke the refresh function from a VBScript, it works perfectly. When I invoke the refresh function with the additional ActiveSheet lines coded below, I get a 1004 error.

    New macro code now results in a 1004 error. When I comment out the last two lines, the refresh function works perfectly.

    Sheets("Sheet1").Select
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Day").ClearAllFilters <--- ERROR 1004 occurs here
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Day").CurrentPage = "4"

    When I get this working, I want to set the value of CurrentPage to the day value of today. So, if today is 3/6/2015, I would want the page filter to be 6.

    Thanks in advance

    I attached the SampleTemplate.xlsm and the Refresh.txt. The Refresh is really a VBS file and should be changed to that extension. This is bare bones, just to demonstrate the concept.
    Attached Files Attached Files
    Last edited by Wintery; 03-06-2015 at 04:52 PM. Reason: Attach Sample

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Set the value of a Pivot Table Page Filter based on the calendar day

    Can you post a sample workbook?
    That line that is giving you an error seems to be correct.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Registered User
    Join Date
    03-06-2015
    Location
    Dallas, Texas
    MS-Off Ver
    2010
    Posts
    4

    Re: Set the value of a Pivot Table Page Filter based on the calendar day

    Posted attachments.

  4. #4
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Set the value of a Pivot Table Page Filter based on the calendar day

    It works fine for me.

  5. #5
    Registered User
    Join Date
    03-06-2015
    Location
    Dallas, Texas
    MS-Off Ver
    2010
    Posts
    4

    Re: Set the value of a Pivot Table Page Filter based on the calendar day

    Just to confirm, you can invoke the refresh script from the .vbs script with no 1004 error? If so, any tips on how to solve/debug that error?

  6. #6
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Set the value of a Pivot Table Page Filter based on the calendar day

    I ran the script and it works fine for me.
    Sorry, I don't see anything wrong with it.

  7. #7
    Registered User
    Join Date
    03-06-2015
    Location
    Dallas, Texas
    MS-Off Ver
    2010
    Posts
    4

    Re: Set the value of a Pivot Table Page Filter based on the calendar day

    When I invoke the VBA code while in Excel, the Page Filter is set correctly, however, when I invoke the VBA function from the VBS script, the page filter is not applied and there is no error. I did solve the 1004 error, but I cannot determine why the Page Filter doesn't stick when invoked from VBS. Any thoughts on how to debug that?

+ 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. Replies: 6
    Last Post: 07-31-2014, 12:56 PM
  2. Pivot Table - can't filter items in page area
    By seyss in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 11-01-2013, 11:33 AM
  3. VBA to change filter for n pivots based on page filter selection for the first pivot
    By shama.arige in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-19-2011, 11:42 AM
  4. Problem setting pivot table page filter
    By VoiceOver in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2007, 09:47 AM
  5. [SOLVED] How do I set up filter for page fields in pivot table?
    By Mitsycat in forum Excel General
    Replies: 3
    Last Post: 05-06-2005, 06:06 PM

Tags for this Thread

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