Run a macro when a Worksheet is clicked/activated

  • Thread starter Thread starter Warren McGoldrick
  • Start date Start date
W

Warren McGoldrick

Hi,

I'm looking for code that runs a macro when a worksheet called "email" is
clicked everytime. I think it's an event macro, but, I can not seem to find
an example.

The macro I want to run is simple

Sheets("email").Select
Range("A1").Select
Application.CutCopyMode = False
ActiveWindow.ScrollRow = 1
ActiveWindow.ScrollColumn = 1

Thanks in advance.

Wazza McG
 
Rightclick on the Email sheet tab and select "View Code".

From the drop down boxes above select Worksheet (from the left) and
Activate (from the right). This should create a procedure for you thus:

Private Sub Worksheet_Activate()

End Sub

Insert your code here in there e.g.

Private Sub Worksheet_Activate()
msgbox "I'm clicked"
End Sub

It will then fire every time the worksheet is activated. If that
Activates isn't what you're after, try Worksheet_SelectionChange or
maybe a combination of the two.

HTH,
Gareth
 
Thankyou Thankyou Thankyou
Gee that was simple!
Much appreciated, I have never used those View Code sheets before - great
stuff.

Wazza McG
 
You're welcome!

Wazza said:
Thankyou Thankyou Thankyou
Gee that was simple!
Much appreciated, I have never used those View Code sheets before - great
stuff.

Wazza McG
 

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