ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   On Sheet select Macro (https://www.excelbanter.com/excel-programming/288656-sheet-select-macro.html)

Colin G Eastwood

On Sheet select Macro
 
Hi there

I need a macro to run, but only when a certain 'WorkSheet' is selected
from within a Workbook containing many worksheets.

Can anyone help me with this?
--
Colin G Eastwood

Brad[_10_]

On Sheet select Macro
 
Use the "SheetActivate" event of the Workbook object.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name = "Sheet2" Then
MsgBox "You selected Sheet2."
End If
End Sub

HTH.

-----Original Message-----
Hi there

I need a macro to run, but only when a

certain 'WorkSheet' is selected
from within a Workbook containing many worksheets.

Can anyone help me with this?
--
Colin G Eastwood
.


Ron de Bruin

On Sheet select Macro
 
If you want to run the macro automatic when you select the sheet you can
use this event in the sheet module

Private Sub Worksheet_Activate()
MsgBox "Hi"
End Sub

Or use this line in your macro to exit the sub if the sheet you want
is not the active one

Sub test()
If ActiveSheet.Name < "yourname" Then Exit Sub
MsgBox "Your code"
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Colin G Eastwood" wrote in message ...
Hi there

I need a macro to run, but only when a certain 'WorkSheet' is selected
from within a Workbook containing many worksheets.

Can anyone help me with this?
--
Colin G Eastwood




Colin G Eastwood

On Sheet select Macro
 
Hi Brad

That did it!

Many thanks

Regards Colin



In article , Brad <anonymous@dis
cussions.microsoft.com writes
Use the "SheetActivate" event of the Workbook object.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name = "Sheet2" Then
MsgBox "You selected Sheet2."
End If
End Sub

HTH.

-----Original Message-----
Hi there

I need a macro to run, but only when a

certain 'WorkSheet' is selected
from within a Workbook containing many worksheets.

Can anyone help me with this?
--
Colin G Eastwood
.




All times are GMT +1. The time now is 11:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com