Solved

Updating a pivottable cache in only certain sheets of a workbook

Posted on 2009-05-05
2
432 Views
Last Modified: 2013-11-25
I have this macro right now that updates all the pivot tables in a workbook, it worked fine for the file that I was using originally because there were only about ten pivot tables to update. But now I would like to use it in a much bigger file that has a lot more pivot tables. Whenever I run the macro below on my current file I get this error message: "Excel cannot complete this task with available resources. Choose less data or close other applications." And then I get a VBA error message that says, "Run-time error '5': Invalid procedure call or argument."

So unless there's a way to make the macro below stop before my computer and Excel get overwhelmed I was just thinking about splitting the macro into three pieces. Where I would run one macro and then it would update the pivot tables in sheets: "Center", "Sony", "Howard", and "Conference". Then i would run another macro that would do it in the sheets after that, etc.

 


Public Sub UpdAllPivots()
  Dim shtThing As Worksheet
  Dim pvtThing As PivotTable
  For Each shtThing In Application.Sheets
    For Each pvtThing In shtThing.PivotTables
      pvtThing.ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, _
        SourceData:="C:\Documents and Settings\shahryarm\Desktop\[Combined 09S 20090407v8.xlsm]Combined Grantee Main Data!R3C4:R50000C252", _
        Version:=xlPivotTableVersion12)
    Next
  Next
End Sub

Open in new window

0
Comment
Question by:hermes829
2 Comments
 
LVL 59

Accepted Solution

by:
Saurabh Singh Teotia earned 500 total points
ID: 24309051
You can use the following code which will do what you are looking for..
Saurabh...

Public Sub UpdAllPivots()
  Dim shtThing As Worksheet
  Dim pvtThing As PivotTable
  For Each shtThing In Application.Sheets
  If shtThing.Name = "Center" Or shtThing.Name = "Sony" Or shtThing.Name = "Howard" Or shtThing.Name = "Conference" Then
    For Each pvtThing In shtThing.PivotTables
      pvtThing.ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, _
        SourceData:="C:\Documents and Settings\shahryarm\Desktop\[Combined 09S 20090407v8.xlsm]Combined Grantee Main Data!R3C4:R50000C252", _
        Version:=xlPivotTableVersion12)
    Next
    End If
  Next
End Sub

Open in new window

0
 

Author Closing Comment

by:hermes829
ID: 31578220
That worked perfectly, thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question