Insert Macro when new worksheet is created

RhodEvans

Board Regular
Joined
Oct 31, 2012
Messages
88
I have a macro that creates new sheets for me from scratch. I need a macro (Sub TOfC) to be inseted in the Private Sub Worksheet_Activate() section. Is there a way of doing this. (If it helps the Sub is in a module called TOC).I am way out of my league with this one, so any help would be VERY greatly received.Thanks in advance for all of your advice.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
If you have a worksheet that already contains the VBA code, the code will be copied when you copy the worksheet.
 
Upvote 0
Appologies I don't think I was clear in my last post/request. The sheet is a dynamic Table of contents that uses hyperlinks to navigate. This is deleted and created new when the spreadsheet is opened so the hyperlinks stay current. So the problem is that is is not copied each time, but created from scratch.
 
Upvote 0
Sorry, I don't understand why you need to delete the sheet and create a new one. Why can't you use the existing sheet after clearing the contents of or deleting all the cells?
 
Upvote 0
Basically because, sometimes I can be an idiot and a little single focussed. So when I thought that that was how It needed doing I lost sight of the fact there was a much simpler way of doing it. Thank you very much I have edited the code so it doesn't delete the sheet each time and am feeling embarassed for wasting your time. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,216,175
Messages
6,129,310
Members
449,499
Latest member
HockeyBoi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top