Pivot tables will not refresh on first try
Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 2 of 2

Thread: Pivot tables will not refresh on first try

  1. #1
    Join Date
    26th May 2012
    Posts
    1

    Pivot tables will not refresh on first try

    I have a macro code that runs a MSQuery returning a table of data to a specified worksheet. I have a pivot table (on a separate worksheet) that uses that table as source data. The same macro that runs the MSQuery also refreshes the pivot table. For some reason the macro must be run twice to get the pivot table to refresh.

    The table of data is imported just fine on the first run. Not sure what the issue is. I have tried multiple variations of code to refresh the pivot tables. I even put the code in twice.

    Thanks for any help.
    dgott

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    25th May 2012
    Posts
    8

    Re: Pivot tables will not refresh on first try

    I have two macros that I use often, one to refresh pivot tables, another to refresh queries, you could try to call them at the end of your code

    VB:
    Public Sub RefreshQueryTables() 
        Dim w As Worksheet 
        Dim q As QueryTable 
        On Error Resume Next 
        For Each w In ActiveWorkbook.Worksheets 
            Application.StatusBar = "Refreshing Query Table: " & w.Name 
            For Each q In w.QueryTables 
                q.Refresh 
            Next 
        Next 
    End Sub 
     
    Public Sub RefreshPivotTables() 
        Dim w As Worksheet 
        Dim p As PivotTable 
        Dim pf As PivotField 
        Dim pi As PivotItem 
        On Error Resume Next 
        For Each w In ActiveWorkbook.Worksheets 
            Application.StatusBar = "Refreshing Pivot Table: " & w.Name 
            For Each p In w.PivotTables 
                For Each pf In p.PivotFields 
                    For Each pi In pf.PivotItems 
                        pi.Delete 
                    Next 
                Next 
                p.RefreshTable 
                p.Update 
            Next 
        Next 
    End Sub 
    
    

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Refresh All Pivot Tables In Workbook
    By HerronShane in forum EXCEL HELP
    Replies: 4
    Last Post: January 20th, 2012, 10:26
  2. Pivot tables Refresh within onClick()
    By rookie_user in forum Excel and/or Access Help
    Replies: 6
    Last Post: August 3rd, 2006, 23:04
  3. refresh pivot tables linked to pivot table
    By macrocyte in forum EXCEL HELP
    Replies: 6
    Last Post: July 28th, 2006, 12:54
  4. Periodic refresh of pivot tables
    By itbitty in forum EXCEL HELP
    Replies: 2
    Last Post: July 22nd, 2006, 01:44
  5. Replies: 11
    Last Post: February 18th, 2004, 06:59

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
  •