+ Reply to Thread
Results 1 to 5 of 5

Autorefresh pivot tables after data import from SQL

  1. #1
    Forum Contributor
    Join Date
    05-28-2010
    Location
    Antwerp, Belgium
    MS-Off Ver
    Office 365
    Posts
    170

    Autorefresh pivot tables after data import from SQL

    I have tons of reports that import data from MSSQL, then based on this data there are also tons of pivot tables.

    I set both SQL data sources and pivot tables to refresh after the file is opened, but of course it has to work in a retarded way
    First it refreshes the pivot tables and then the SQL data.. So the pivot tables are not showing the latest data in the end.

    Any solutions for that?
    VBA is also an option..

    Thanks!

  2. #2
    Registered User
    Join Date
    06-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Autorefresh pivot tables after data import from SQL

    Use the below code by changing the worksheet name

    Dim ws As Worksheet
    Dim pivot As PivotTable
    'Dim z As PivotCache
    For Each ws In oWB_Data_File.Worksheets
    If ws.PivotTables.Count > 0 Then
    For Each pivot In ws.PivotTables
    pivot.RefreshTable
    Next pivot
    End If
    Next

  3. #3
    Forum Contributor
    Join Date
    05-28-2010
    Location
    Antwerp, Belgium
    MS-Off Ver
    Office 365
    Posts
    170

    Re: Autorefresh pivot tables after data import from SQL

    Thank you!

    I have to put this on each worksheet, right?

    and just to be sure, the "ws" has to be changed to the worksheet name, right?

  4. #4
    Registered User
    Join Date
    06-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Autorefresh pivot tables after data import from SQL

    you have to use replace oWB_Data_File with thisworkbook and paste into workbook code section and run

  5. #5
    Forum Contributor
    Join Date
    05-28-2010
    Location
    Antwerp, Belgium
    MS-Off Ver
    Office 365
    Posts
    170

    Re: Autorefresh pivot tables after data import from SQL

    I don't get it.. it doesn't save it. Every time I reopen the file its gone.

    I do:
    Right click on some sheet => View code => Open ThisWorkbook => Paste this:

    Dim ws As Worksheet
    Dim pivot As PivotTable
    'Dim z As PivotCache
    For Each ws In test.xlsm.Worksheets
    If ws.PivotTables.Count > 0 Then
    For Each pivot In ws.PivotTables
    pivot.RefreshTable
    Next pivot
    End If
    Next

    And SAVE AS Macro enabled excel file.

    What am I doing wrong?

    Thanks

+ 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. [SOLVED] Pivot Table Autorefresh!!
    By Veolia in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-18-2014, 05:36 AM
  2. Pivot Table Autorefresh
    By Veolia in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-14-2014, 01:09 PM
  3. Replies: 2
    Last Post: 09-09-2013, 01:13 PM
  4. Validating Data Between 2 Pivot Tables (Pivot Tables Don't Line Up)
    By JohnGC84 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 06-18-2013, 05:07 PM
  5. [SOLVED] Change and autorefresh pivot table as per the selection (Very tough one )
    By amitav in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-18-2012, 10:51 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