+ Reply to Thread
Results 1 to 12 of 12

Auto-refresh pivot tables in worksheet_change event?

  1. #1
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Auto-refresh pivot tables in worksheet_change event?

    Hi all, can someone suggest to me the code that should be entered in a Worksheet_Change() routine that would automatically refresh all pivottables which are tied to that worksheet (after the worksheet has recalculated, of course)?

    Thanks
    Last edited by 1eyedjack; 03-01-2012 at 12:32 PM. Reason: Solved- thanks

  2. #2
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Auto-refresh pivot tables in worksheet_change event?

    use this in module of sheet
    Please Login or Register  to view this content.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Auto-refresh pivot tables in worksheet_change event?

    Yay, thanks

  4. #4
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Auto-refresh pivot tables in worksheet_change event?

    I may have spoken too soon.
    The pivot tables need not be, and indeed generally will not be, in the same worksheet as the source data.
    Currently this code as suggested appears to have no noticeable effect. It certainly is not refreshing the pivot tables in other worksheets.

  5. #5
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Auto-refresh pivot tables in worksheet_change event?

    try this then
    Please Login or Register  to view this content.
    Last edited by tom1977; 03-01-2012 at 10:45 AM.

  6. #6
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Auto-refresh pivot tables in worksheet_change event?

    Still no joy.

    Hopefully the attached illustrates the problem.

    The intended effect is:
    Change the numerical values in either of Source!C3 or Source!C4 and the value in Pivot!B4 should recalculate without the requirement refresh manually.

    If it makes a difference: Excel 2003.

    Thanks
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Auto-refresh pivot tables in worksheet_change event?

    there is something wrong with your file but maybe the change of solution will help
    put this code into module of sheet with pivots
    Please Login or Register  to view this content.
    when You activate this sheet the pivots will refresh automatically
    Last edited by tom1977; 03-01-2012 at 10:44 AM.

  8. #8
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Auto-refresh pivot tables in worksheet_change event?

    Still no joy. I have tried both revised solutions (removing the If statement from the worksheet_change code, and including a worksheet activate code in the pivot sheet). But it still does not refresh except manually. Revised workbook incorporating those suggestions is attached to this reply. Tom1977, what causes you to conclude that there is something wrong with the file itself?

    Incidentally, if I can get a solution to work that ONLY involves putting code into the source sheet (or general module or under the workbook itself) then that would be ideal, as I may want to grant the end user permission to add further pivot tables in additional sheets, and I would not want to put them to the trouble of having to add VBA code to the new sheets. If I have to live without that ideal then so be it. So far, I have not been able to get either approach to work.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Auto-refresh pivot tables in worksheet_change event?

    Addendum. This may be of interest:

    If I open the file from disk, I get no error messages. It doesn't refresh the pivot table, but neither does it present an error message. The same applies if I download the file from the web page and save it to disk before then opening it from that location.

    But if I open it directly by clicking on the link in this web page, then when I activate the pivot sheet I get

    Run-time error 1004: Cannot open pivottable source file '[PivotAutochange[1].xls]Source'.
    Then the debug line highlighted is the line
    Please Login or Register  to view this content.
    in the Worksheet_Activate code behind the pivot sheet.

  10. #10
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Auto-refresh pivot tables in worksheet_change event?

    Humm.
    It now seems to be working and auto-refreshing. I just closed Excel and re-opened it and the Worksheet_Activate code did the trick. Not an ideal solution because as I say the code resides in the pivot table sheet rather than (preferred) in the source data sheet. I shall leave the thread marked unsolved for the time being in case anyone has a suggestion to get over that hurdle.

    Anyway, the current (half)working model is now attached hereto.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Auto-refresh pivot tables in worksheet_change event?

    Phew!! Solved it (I think). At least it seems to work for now.
    In the code behind the ThisWorkbook I put

    Please Login or Register  to view this content.
    Thanks for all the help, guys. Couldn't have done it without you.

    Quite why the Worksheet_Change() solution didn't work remains a mystery. I don't NEED to know why, but if anyone has any insight it will aid my education.
    Last edited by 1eyedjack; 03-01-2012 at 12:31 PM.

  12. #12
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Auto-refresh pivot tables in worksheet_change event?

    Not sure - it worked for me in your sample file.
    Good luck.

+ 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