Reputation: 9
Just learning about advanced functions of excel/vb,
I'm having trouble finding just how to refresh 1 worksheet in a workbook. Currently I have
Sub my_onTime()
Application.OnTime Now + TimeValue("00:00:05"), "refresh_FiveSeconds"
End Sub
Sub refresh_FiveSeconds()
ThisWorkbook.RefreshAll
my_onTime
End Sub
This refreshes the workbook but cant find anything online which I just want to refresh worksheets seperately
Upvotes: 0
Views: 5308
Reputation: 43595
If you want to refresh all pivot tables in all worksheets, consider looping through the worksheets and working with the pivot tables:
Public Sub TestMe()
Dim ws As Worksheet
Dim pt As PivotTable
For Each ws In Worksheets
For Each pt In ws.PivotTables
pt.RefreshDataSourceValues
pt.RefreshTable
pt.RepeatAllLabels
Next pt
Next ws
End Sub
If you want to refresh just specific worksheets, then you may introduce some type of a condition in the loop, e.g. If ws.Name = "Sheet10WithPivots" Then
Upvotes: 1