![]() |
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? |
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. |
How do I write VB to run Macro when sheet selected?
Think Mark copied the wrong event declaration:
Private Sub Worksheet_Activate() End Sub is what he describes. -- Regards, Tom Ogilvy "mark" wrote in message ... 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. |
How do I write VB to run Macro when sheet selected?
Think Mark copied the wrong event declaration:
Yep, I sure did. Thanks for the catch. |
All times are GMT +1. The time now is 05:15 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com