ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheet Activate Event (https://www.excelbanter.com/excel-programming/315261-worksheet-activate-event.html)

Jason

Worksheet Activate Event
 
I have the following code, which is being run when a worksheet called "RV
Summary" is being selected.

Private Sub Worksheet_Activate()

Sheets("Crosstab").Activate
ActiveSheet.PivotTables("PivotTable_Statistics").P ivotCache.Refresh
Sheets("RV Summary").Select

End Sub

Whenever "RV Summary" is selected, I want a pivot table located on another
sheet (Crosstab) to get refreshed, and then I want it to maintain "RV
Summary" as the active sheet (essentially the user will not even know that
this pivot is being updated when they select (RV Summary). The problem is
that this gets into a never ending loop. Is their a way to alter this or
make it so that it only performs this action once and then just goes back to
RV Summary. Thanks.

Myrna Larson

Worksheet Activate Event
 
You don't need to select and/or activate things to work with them and doing so
may cause real problems if you don't code it correctly. YOu've run into that
-- inadvertent recursion.

At the very least, if you *had* to activate a different sheet, you would
disable events (Application.EnableEvents = False), then activate the other
sheet, then re-enable just before the routine ends.

But there is no need to change sheets here. Try it this way:

Private Sub Worksheet_Activate()
Sheets("Crosstab").PivotTables("PivotTable_Statist ics").PivotCache.Refresh
End Sub


On Fri, 29 Oct 2004 14:10:05 -0700, "Jason"
wrote:

I have the following code, which is being run when a worksheet called "RV
Summary" is being selected.

Private Sub Worksheet_Activate()

Sheets("Crosstab").Activate
ActiveSheet.PivotTables("PivotTable_Statistics").P ivotCache.Refresh
Sheets("RV Summary").Select

End Sub

Whenever "RV Summary" is selected, I want a pivot table located on another
sheet (Crosstab) to get refreshed, and then I want it to maintain "RV
Summary" as the active sheet (essentially the user will not even know that
this pivot is being updated when they select (RV Summary). The problem is
that this gets into a never ending loop. Is their a way to alter this or
make it so that it only performs this action once and then just goes back to
RV Summary. Thanks.




All times are GMT +1. The time now is 07:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com