Macro to refresh pivot tables produces run-time error 440

L

Legacy 327851

Guest
Hi there,

I'm using Excel 2013 and have a workbook with 5 sheets of data, all from different external data sources.

I've then created a new sheet which is basically my report. It has a drop-down for a user to select their ID, and this then updates some vlookups, but the reason for the macro is that I have 3 pivot tables in the report. To make it easier for users who would be easily confused by having to refresh the tables I've created a macro that refreshes them all when you hit the big button that says 'run report'.


This is my first experience with macros so I have simply hit Record and then refreshed each of my pivot tables in turn, and then stopped recording. I can copy out the code if needed.

Now - the problem. The macro works fine for me, and for about 90% of the users. I have a couple of people who get an error though, and I can't figure out if there's something wrong with the macro, or elsewhere. I suspect elsewhere as surely it would affect everyone otherwise?

The error is Run-time error '440': Method 'Refresh' of object 'PivotCache' failed.

Can anyone help?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Could you copy the code? I suspect you have soething like Version:=xlPivotTableVersion14 in your code and Are those users using another version of excel...

Also do they accept the security question about running macro?
 
Upvote 0
Could you poste the code?

I suspect you have something like
Code:
[COLOR=#333333][FONT=Segoe UI]Version:=xlPivotTableVersion14 [/FONT][/COLOR]

and some users to use a different version. If so, try to erase this part and see if it still works.

Sorry for 2X messaging
 
Upvote 0
Could you copy the code? I suspect you have soething like Version:=xlPivotTableVersion14 in your code and Are those users using another version of excel...

Also do they accept the security question about running macro?


Thanks. Here's the code:

Code:
Sheets("Report").Unprotect Password:="[REDACTED]"
    Sheets("TaskData").Range("I2,J10000").NumberFormat = "DD/MM/YYYY"
    Range("F2").Value = "Report date: " & Date
    Range("C28").Select
    Sheets("Report").PivotTables("PivotTable2").PivotCache.Refresh
    Range("I6").Select
    Sheets("Report").PivotTables("PivotTable5").PivotCache.Refresh
    Range("I28").Select
    Sheets("Report").PivotTables("PivotTable4").PivotCache.Refresh
    Sheets("Report").Protect Password:="[REDACTED]"


I'll ask them to double check they are accepting macros. We are all using Excel 2013.
 
Upvote 0
Hi,

Your code seems perfectly valid. Maybe some ID do not have all pivots? I would normally use the code below (I believe it works even on code protected sheets)

Code:
ActiveWorkbook.RefreshAll
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top