Solved

Updating a pivottable cache in only certain sheets of a workbook

Posted on 2009-05-05
2
421 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now