+ Reply to Thread
Results 1 to 7 of 7

VBA Macro to refresh PivotTable.

Hybrid View

  1. #1
    Registered User
    Join Date
    05-21-2015
    Location
    Rochester
    MS-Off Ver
    2010
    Posts
    10

    VBA Macro to refresh PivotTable.

    Currently I'm running a Query that stores all the information it gets out of it into a table called "Query" on the 'ValidationTool' page. I can edit the dates the query goes through, by editing cell C1 example (5/22/2015 or 5/29/2015). I have another table called "Rooster" that helps to analyses the data and is on the 'Department Rooster' page. Then I have a PivotTable called 'Analysis' which helps to summarize all the data from the "Rooster" table into neat information.

    Yet what my main issues is I can't figure out how to use VBA to refresh the PivotTable every time I enter a new data and the new query results show up. Any help on this would be much appreciated.

  2. #2
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: VBA Macro to refresh PivotTable.

    This is the basic code to refresh a pivot table.

    Worksheets("Sheet1").PivotTables("PivotTable1").RefreshTable
    You might be able to attach it to the worksheet change event on the ValidationTool page.
    Some people volunteer in soup kitchens or hospitals. I choose to make the world better by trying to help you with Excel. We're all learning.

    <---Click * Add Reputation for all helpful comments. It's like giving a smile.
    Forum Rules: How to mark your post [Solved] and have a happier, Excel enriched life.

  3. #3
    Registered User
    Join Date
    05-21-2015
    Location
    Rochester
    MS-Off Ver
    2010
    Posts
    10

    Re: VBA Macro to refresh PivotTable.

    I tried
     
    Private Sub Worksheet_Change(ByVal Target As Range)
        Worksheets("ValidationTool").PivotTables("Analysis").RefreshTable
    End Sub
    And have received and error when attempting to change the information in cell C1 and the refreshing begins.
    It is a Run-time error '1004': RefreshTable method of PivotTable Class failed

  4. #4
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: VBA Macro to refresh PivotTable.

    This would also refresh every pivot table in the workbook:
    For Each pvt In ActiveWorkbook.PivotCaches
          pvt.Refresh
     Next pvt

  5. #5
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: VBA Macro to refresh PivotTable.

    Are you sure you have the sheet name and the pivot table name correct?

    You could also try this:
    Worksheets("ValidationTool").PivotTables(1).RefreshTable

  6. #6
    Registered User
    Join Date
    05-21-2015
    Location
    Rochester
    MS-Off Ver
    2010
    Posts
    10

    Re: VBA Macro to refresh PivotTable.

    Thanks for you help. It didn't work, but I decided to just make a Refresh button that corresponds to a macro I recorded. For some reason every time I tried one of the above codes it ended up making my excel go crazy. Yet once again thanks for trying to help poor ol' me.

  7. #7
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: VBA Macro to refresh PivotTable.

    Sorry. I'm glad you got something to work.

+ 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. How to refresh only one Pivottable via VBA ????
    By Excelbat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2015, 01:42 PM
  2. [SOLVED] PivotTable auto refresh
    By ooberandy in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 12-05-2014, 12:20 PM
  3. Replies: 0
    Last Post: 01-07-2013, 08:39 PM
  4. PivotTable/auto refresh
    By Trainee in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-16-2011, 05:19 PM
  5. PivotTable.Refresh woes
    By JeremyR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2007, 09:04 PM

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