Hi all,
I have a spreadsheet with ~40 tabs. Each tab has a couple of pivot charts which are set to refresh using the worksheet_change sub. The code I have within each tab is as follows;
The issue I have is that as more tabs are added the time taken to add each new tab is increasing, up to the point where it takes a minute or so to add a new tab. I suspect that each new addition is forcing a refresh of all pivot tables in all tabs, hence the fairly linear increase in time from <5 tabs upto >40.
Is this what is happening? If so can I change the code so this no longer happens?
I have a spreadsheet with ~40 tabs. Each tab has a couple of pivot charts which are set to refresh using the worksheet_change sub. The code I have within each tab is as follows;
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'If data on this worksheet changes, refresh the pivot tables
Application.EnableEvents = False
ActiveSheet.Unprotect
ActiveSheet.PivotTables("PivotTable1").RefreshTable
ActiveSheet.PivotTables("PivotTable2").RefreshTable
ActiveSheet.Protect AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFiltering _
:=True, AllowUsingPivotTables:=True
Application.EnableEvents = True
End Sub
The issue I have is that as more tabs are added the time taken to add each new tab is increasing, up to the point where it takes a minute or so to add a new tab. I suspect that each new addition is forcing a refresh of all pivot tables in all tabs, hence the fairly linear increase in time from <5 tabs upto >40.
Is this what is happening? If so can I change the code so this no longer happens?