+ Reply to Thread
Results 1 to 10 of 10

Updating data source and refreshing all pivot tables through VBA.

  1. #1
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Updating data source and refreshing all pivot tables through VBA.

    Hi all,

    I have a spreadsheet containing several pivot tables, all based on the same data source. From time to time, the data source is updated is additional rows (column A never contains any empty cells), therefore I created the following macro to update the data source of all pivot tables as well as refreshing those:

    Please Login or Register  to view this content.
    However it seems to fail when applying the SourceName variable. I am not sure where the issue could lie, I used F8 and watched the variables but the macro seems to do something completely different than what at I am expecting (i.e. simply update the source of each pivot tables using range A1:AX1 to the bottom of the 'MasterSheet' worksheet).

    Any help would be appreciated. Thanks.

    PS: I also used

    Please Login or Register  to view this content.
    instead of

    Please Login or Register  to view this content.
    but this did not help.
    Last edited by Folshot; 11-24-2013 at 12:30 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Updating data source and refreshing all pivot tables through VBA.

    Try this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Re: Updating data source and refreshing all pivot tables through VBA.

    Thanks AlphaFrog,

    The changes make sense but unfortunately the same issue remains, i.e. the macro stops when processing:

    Please Login or Register  to view this content.
    I have attached a cutdown version of the spreadsheet containing the macro, not sure if this helps.

    Test5.xls

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Updating data source and refreshing all pivot tables through VBA.

    I got this to work with your Test5 workbook.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Re: Updating data source and refreshing all pivot tables through VBA.

    I got this to work with your Test5 workbook.
    Could you please upload the version of the spreadsheet you now have? I have cut & pasted the last set of code you provided but still encounter the same issue

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Updating data source and refreshing all pivot tables through VBA.

    Quote Originally Posted by Folshot View Post
    Could you please upload the version of the spreadsheet you now have? I have cut & pasted the last set of code you provided but still encounter the same issue
    Here it is.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Re: Updating data source and refreshing all pivot tables through VBA.

    That's really strange, the macro you have created in the latest Test5.xls file seems to work fine for me, but if I cut & paste the code into my file (which contains exactly the same source data and pivot tables) or any other file, I get again the run time error 1004... really weird... I am currently investigating.

  8. #8
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Re: Updating data source and refreshing all pivot tables through VBA.

    I am now using this code, it never generates any errors and seem to work fine:

    Please Login or Register  to view this content.
    I have one outstanding issue though, I want the new range to be from columns "A1:D1" until last row, but the above code select the whole table, i.e. from "A1:J1) until the last row.

    I used this code as an alternative but this did not help:

    Please Login or Register  to view this content.
    Any idea and making sure the range is only for specific columns rather than all of them?

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Updating data source and refreshing all pivot tables through VBA.

    Remove the .CurrentRegion property and the 1 from D1


    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Re: Updating data source and refreshing all pivot tables through VBA.

    Thanks AlphaFrog, it works perfect!

+ 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. Change Pivot Source Data in multiple pivot tables
    By jacol in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 05-20-2014, 06:18 AM
  2. Replies: 3
    Last Post: 02-27-2012, 08:03 PM
  3. Pivot Tables and VBA: Changing Contents in Data Area and updating the Data Source
    By kyrgyzstanart in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-22-2011, 11:11 AM
  4. updating pivot tables using dynamic data source
    By dab4211 in forum Excel General
    Replies: 3
    Last Post: 07-24-2006, 04:45 PM
  5. Updating source data while in Pivot Table
    By Carim in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2005, 10:06 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