PDA

View Full Version : Solved: Run Macro When Worksheet Is Selected



pmorris
11-02-2007, 03:57 AM
Hi All

I have been going through the forum for a while now and can't find what I need. :banghead:

Is it possible to run a macro when a user selects a worksheet? The worksheet I have contains a pivot table which I want to automatically update when the worksheet is selected. I have a macro that automatically updates the pivot but I have to select it to run it. What I want is for the macro to run automatically when the worksheet is selected.

Please could someone help!!!

Many Thanks

Paul

figment
11-02-2007, 05:02 AM
in your VBA editor, put the update code in this sub

Private Sub Worksheet_Activate()

End Sub

and put the sub on the sheet with the pivet table

example the folowing workbook. adds 1 to range("A1") everything you select sheet1

7166

the only down side, is that this trigger only triggers if you ar selecting the sheet from anouther excel workbook or anouther excel sheet. if you selecting it from anouther application, then it will not trigger.

pmorris
11-02-2007, 06:13 AM
That worked well

Thanks