Private Sub Worksheet_Deactivate()
*** your code ***
End Sub
To get to the code sheet - right click on the sheet tab and select "View
Code". This will take you to the code window. Above the 'blank' page are 2
edit boxes. From the one on the left - select "Worksheet", and from the one
on the right - select "Deactivate". Any code you put in here will run when
you select another worksheet tab.