Using VBA in excel, how would I execute a macro every time I switched between sheets?

2 replies [Last post]
User offline. Last seen 3 years 15 weeks ago. Offline
Joined: 10/26/2008
Posts: 11

Hi all,

Using VBA, how could I have a macro executed automatically every time I select a new sheet within the workbook. To make it even more challenging, how could I set it so up so a different macro is executed depending on which sheet I had selected.

Thanks for any help

Chris (running excel 93)

User offline. Last seen 4 weeks 4 days ago. Offline
Joined: 06/02/2008
Posts: 15
See the example below

See the screenshot below. Go to VBE window , double click and then put this code in VBE and between these you can do whatever you want.

This will execute as soon as you activate a sheet. I hope this helps.

 

Activate event VBA

 

Joined: 01/26/2010
Posts: 1
With worksheet activate
With worksheet activate event, put VBA in local sheet (right click tab, select view code)