Hello, can anybody help to resolve error below. I am only trying to update pivot with the sheets stated below.
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
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