Inserting code to call a routine when creating a worksheet

J

John

I have a macro that creates a new sheet from a template. Once the new sheet
is set up, I need to add a Call to another macro every time the sheet is
selected by the user so that the sheet can be populated w/ current info.

How & to where do I copy a short routine to do this call?

What is the form of the Sub stmt that executes only when the user selects
the worksheet tab and not when other activity takes place on the sheet?

I appreciate your help, -John
 
J

JE McGimpsey

One way:

Put this in the worksheet code module:

Private Sub Worksheet_Activate()
Call MyUpdateMacro
End Sub
 
J

John

This helps a lot. Now, what code do I use to copy these three lines into the
place where it needs to go after I create the worksheet so it gets executed
when the worksheet is selected?
 
J

JLGWhiz

What code are you using to create the new sheet?

John said:
This helps a lot. Now, what code do I use to copy these three lines into the
place where it needs to go after I create the worksheet so it gets executed
when the worksheet is selected?
 
G

Gord Dibben

If OP simply copies the sheet, the code will go with it.


Gord Dibben MS Excel MVP
 
G

Gord Dibben

I thought yours was a valid question and my comment was really for the OP.

Should have posted a reply there instead.


Gord
 
J

John

Gord, thank you for your response. It answered my question. It hadn't dawned
on me that the code would copy with the copy of the sheet- I thought I had to
recreate it on the new worksheet.

Frankly, coming from my frame of mind, I felt JLGWhiz's response was a
little sarcastic and unhelpful. But it is always difficult to read someone's
frame of mind via just a short post on the internet.

Thx again, John
 

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

Top