execute macro on Worksheet selection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to have a macro execute every time a specific Worksheet is
selected.

Thank You,
Bob carter
 
Hi Bob

Try:
'=============>>
Private Sub Worksheet_Activate()
Call MyMacro
End Sub
'<<=============

This is worksheet event code and should be pasted
into the worksheets's code module (not a standard
module and not the workbook's ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.

In a standard module:

Alt-F11 to open the VBE,
Tools | Insert | Module
paste the following
code:
'=============>>
Public Sub MyMacro()
'Your code, e.g.:
MsgBox Prompt:="Hi!"
End Sub
'<<=============
 
Thanks Norman, the macro does exactly what i wanted.

Bob Carter
Douglas, MA USA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top