View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mark Mark is offline
external usenet poster
 
Posts: 989
Default How do I write VB to run Macro when sheet selected?

I am trying to write VB code to cause a Macro to run when a particular
worksheet is selected. How do I write this code and where do I place it?


The code is the same as any other VB code... whatever you need it to do.

You place it in the worksheet's code mudule...

In the VB window, press View-Project Explorer
Double click the sheet that you want the code to work with
Use the drop box in the upper left and select 'Worksheet'
Use the drop box in the upper right to select 'Activate'

When you do that, a subroutine will come up that looks like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

Each time the sheet is activated, that code will run.