hermes829
asked on
Updating pivot tables in a workbook
Whenever I run the macro below more than once 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."
I need to apply a macro that updates pivot table ranges across an entire workbook, my first attempt at this was to make one macro but I got the error message above. What I did then was to split the macro into three pieces. I 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. I can update the first set of sheets but when I try and run the second maco half way through I get the error message that I got above.
I need to apply a macro that updates pivot table ranges across an entire workbook, my first attempt at this was to make one macro but I got the error message above. What I did then was to split the macro into three pieces. I 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. I can update the first set of sheets but when I try and run the second maco half way through I get the error message that I got above.
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
ASKER
Thanks I'm afraid that the dataset is the size it is. We just have too many pivot tables referencing a dataset that's too big to continue using this type of format. Do you have any suggestions for database programs to switch to?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome thank you very much for this information.
Have you tried this with a smaller dataset? Your 50,000 rows and 252 columns is 12,600,000 cells of data. Each Pivot Table by default holds a copy of the data so you could truly be running out of resources. If you have 10+ pivot tables it may be too much without setting PT options to disable "Save source data with file". If the dataset does not truly have 50,000 rows and you used that number to make sure you catch the bottom of the data then perhaps you can use a dynamic range name to define the data area.
Some sample code is here - http://www.experts-exchang
HTH,
Jerry