+ Reply to Thread
Results 1 to 9 of 9

Using VBA to change a pivot table filter, refresh the report and set up a refresh delay

  1. #1
    Registered User
    Join Date
    03-01-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2010
    Posts
    64

    Smile Using VBA to change a pivot table filter, refresh the report and set up a refresh delay

    Hello

    I'm going round in circles trying to figure out the following:

    I have a pivot table that displays cumulative percentages over time (the time period in question being months), with a report filter at the top allowing the user to pick a month. Using some clever macro I want to be able to do the following:

    1) Running the macro will change the month in the filter sequentially (Jan 12, Feb 12, Mar 12 etc)
    2) After each change is made to the filter the report refreshes itself
    3) Each occurence last for a few seconds (in this instance let's say 5)

    In other words, as soon as I select the macro it will change the filter, refresh the report, keep the results up on screen for a few seconds and then change the filter to the next month in sequence, refresh and display etc etc

    Is this possible? Any help is gratefully received

    Many thanks
    Kenny

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Using VBA to change a pivot table filter, refresh the report and set up a refresh dela

    is the report filter part of the pivot table itself (in which case the refresh is automatic) or something you have built?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    03-01-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Using VBA to change a pivot table filter, refresh the report and set up a refresh dela

    Hi

    Yes it is, at the moment it's just a standard pivot table that I've set up

    Thanks
    Kenny

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Using VBA to change a pivot table filter, refresh the report and set up a refresh dela

    in that case this oughta do it (all in a normal module)
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-01-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Using VBA to change a pivot table filter, refresh the report and set up a refresh dela

    Hello again

    Thanks for that code, I've entered it and firstly ran the CycleFilters macro. After the month correctly changed to the next in sequence, the following message appeared:

    "Cannot run the macro "...nextItem'. The macro may not be available in this workbook or all macros may be disabled.

    I also get the same error message if I try running the NextItem macro. The workbook is saved as macro-enabled, and I've entered the code into a standard module within the active workbook. Do you know what this error means and is there anything you can offer as help please (I'm very much a VBA novice so your help is appreciated)

    Many thanks
    Kenny

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Using VBA to change a pivot table filter, refresh the report and set up a refresh dela

    Are you sure it is in a standard module - eg Module1 and not a worksheet or ThisWorkbook module? Does it appear in the macros dialog list?
    Remember what the dormouse said
    Feed your head

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Using VBA to change a pivot table filter, refresh the report and set up a refresh dela

    is it definitely in a normal module?

  8. #8
    Registered User
    Join Date
    03-01-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Using VBA to change a pivot table filter, refresh the report and set up a refresh dela

    Sorry! My bad, I'd entered it into the worksheet, just moved it into a module and it now works fine, thanks

    Just for my own understanding, why does putting the code into a worksheet instead of a module cause the problem I had before?

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Using VBA to change a pivot table filter, refresh the report and set up a refresh dela

    if you put it in a worksheet module, it becomes a method of that sheet and you have to call it accordingly - sheet1.nextitem instead of just nextitem for instance.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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