UPDATE PIVOT VBA NOT WORKING/error

JOHATUP

New Member
Joined
May 26, 2023
Messages
38
Office Version
  1. 2013
Platform
  1. Windows
Hello, can anybody help to resolve error below. I am only trying to update pivot with the sheets stated below.
1718288335400.png


1718288303787.png


Sub UpdateAllPivotTables()
Dim wsData As Worksheet
Dim wsAging As Worksheet
Dim wsDailyPending As Worksheet
Dim wsPivot As Worksheet
Dim wsPivot2 As Worksheet
Dim pt As PivotTable

' Set references to the worksheets
Set wsData = ThisWorkbook.Sheets("Data")
Set wsAging = ThisWorkbook.Sheets("Aging")
Set wsDailyPending = ThisWorkbook.Sheets("Daily Pending")
Set wsPivot = ThisWorkbook.Sheets("Pivot")
Set wsPivot2 = ThisWorkbook.Sheets("Pivot2")

' Update pivot table in "Pivot" sheet from "Daily Pending" sheet
For Each pt In wsPivot.PivotTables
pt.ChangePivotCache wsDailyPending.PivotTables(1).PivotCache
pt.RefreshTable
Next pt

' Update all pivot tables in "Pivot2" sheet from "Data" sheet
For Each pt In wsPivot2.PivotTables
pt.ChangePivotCache wsData.PivotTables(1).PivotCache
pt.RefreshTable
Next pt

' Update all pivot tables in "Aging" sheet from "Data" sheet
For Each pt In wsAging.PivotTables
pt.ChangePivotCache wsData.PivotTables(1).PivotCache
pt.RefreshTable
Next pt
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
What happens if you ask it for wsDailyPending.PivotTables.Count (at that breakpoint)?
 
Upvote 0
Sorry. When you run your original code and get the original error, click Debug, then open the Immediate window (Ctrl+G) and on a blank line type this and press enter.

VBA Code:
?wsDailyPending.PivotTables.Count

It should either give you a number or an error message.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

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