Pivot Table Refresh

another31

New Member
Joined
Feb 12, 2018
Messages
5
Hi All,

I wondering if someone would be able to help.

I have a workbook that has a sheet labelled as "Pivots" with the data kept in another sheet called "Calls"...I am trying to find a way that would allow me to update the data in "calls" and for the pivots (named as PivotTable1 to 9) to refresh automatically with only the latest values showing (I run the report in the morning for the previous day).

The layout of the PTs are:
ROWS:
Date
Description

Columns:
Values (Sum of total calls & Sum of Total Talk Time)

I have tried the below on the "Calls" sheet in VBA under Worksheet and Change but this requires me to have all of the dates showing under the filter (when I need the latest date only showing):

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Sub Refresh_All_Pivot_Table_Caches()
'Refresh all pivot caches in the workbook.
'Pivot tables are automatically refreshed when cache is refreshed.


Dim pc As PivotCache

  'Refresh all pivot tables
  For Each pc In ThisWorkbook.PivotCaches
    pc.Refresh
  Next pc
  

End Sub

Many thanks for any help / advice.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
how are you filtering your pivot? is the dates field in the row labels or report filter? if you have dates in the report filter you can try use this

Code:
ActiveWorkbook.RefreshAll
Sheets("Pivots").PivotTables("PivotTable1").PivotFields("Dates").CurrentPage = Date-1

assuming your dates field is called "Dates". the code is meant to change the report filter to whats after the =. the Date code gives today and Date-1 is meant to get yesterday

not sure how to get it to loop through all your tables though. maybe something like this?

Code:
Dim i as integer
ActiveWorkbook.RefreshAll
For i = 1 to 9
Sheets("Pivots").PivotTables("PivotTable" & i).PivotFields("Dates").CurrentPage = Date-1
next i

hope that works
 
Upvote 0
Hi fhqwgads,

Thanks for the above, the date is filtered in the row column (apologies, I thought it was in the report part)...not sure if the 1st part would run through OK if that's the case?

For the 2nd part, if I put this under "Calls" and Workbook & Change...I get: "Run-time error '1004' - Unable to set the CurrentPage property of the PivotField class"

Does this need to be under Workbook and Change under Sheet1 (Pivots)?

Many thanks for all of your help,

another31
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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