Forum

Refresh pivot in sp...
 
Notifications
Clear all

Refresh pivot in specific intervals

6 Posts
2 Users
0 Reactions
96 Views
(@gk2021)
Posts: 18
Eminent Member
Topic starter
 

Hi Mynda,

Please assist me to refresh the pivot which is updated based on the source data which appends data in 15 minute intervals.

I have tried a few VB codes from the internet, but did not help.

Warm Regards
GK

 
Posted : 07/04/2021 11:28 pm
(@catalinb)
Posts: 1937
Member Admin
 

Use this code in a standard module:

Option Explicit

Public TimeInterval As Double

Sub RefreshQuery()

ThisWorkbook.Worksheets("SheetName").ListObjects("TableName").QueryTable.Refresh BackgroundQuery:=False
Debug.Print Now()
TimeInterval = Now() + TimeSerial(0, 15, 0)
Application.OnTime TimeInterval, "RefreshQuery"
End Sub

Sub StopTimer()
Application.OnTime earliesttime:=TimeInterval, procedure:="RefreshQuery", schedule:=False
End Sub

The following code should be placed in ThisWorkbook module:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTimer
End Sub

Private Sub Workbook_Open()
RefreshQuery
End Sub

 
Posted : 09/04/2021 10:45 pm
(@gk2021)
Posts: 18
Eminent Member
Topic starter
 

Thank you Catalin Bombea, will try that today and revert to you.

Regards
~GK

 
Posted : 09/04/2021 11:48 pm
(@gk2021)
Posts: 18
Eminent Member
Topic starter
 

Bad luck mate, getting Run Time Error '9'. Subscript out of range.

Let me know if this information is enough.  I had put your first code by create a module under Pivot and the second piece of code in the Pivot worksheet itself.

Regards
~GK

 
Posted : 10/04/2021 12:16 am
(@catalinb)
Posts: 1937
Member Admin
 

The code provided will refresh a power query.

(ThisWorkbook.Worksheets("SheetName").ListObjects("TableName").QueryTable.Refresh )

To refresh a pivot table:

ThisWorkbook.Worksheets("SheetName").PivotTables("PivotName").PivotCache.Refresh

I assume that you will change the generic names used for sheet and pivot name, right?

[...] and the second piece of code in the Pivot worksheet itself.

Please read more carefully the instructions, the second code must be placed into ThisWorkbook module, NOT a sheet module.

The following code should be placed in ThisWorkbook module:

 
Posted : 10/04/2021 12:26 am
(@gk2021)
Posts: 18
Eminent Member
Topic starter
 

Thanks mate, appreciate your help.

 

~GK

 
Posted : 12/04/2021 10:32 am
Share: