+ Reply to Thread
Results 1 to 7 of 7

adding a worksheet with a pre-specified private sub.

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    Tilburg, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    13

    adding a worksheet with a pre-specified private sub.

    Hi all,

    I want to write a code that adds worksheets to my existing workbook. I know how to add sheets, but at the same time, I want the sheets that are created to contain a private sub that runs when I change a range of target cells on this newly created sheet later on. Does anyone know if this is possible? Thanks a million!

    Bram

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Why not use the workbook level SheetChange event?

    That will be triggered by a change in any worksheet in the workbook.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    04-13-2013
    Location
    Gliwice, Poland
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: adding a worksheet with a pre-specified private sub.

    and you can exclude specified sheets with
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-18-2012
    Location
    Tilburg, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: adding a worksheet with a pre-specified private sub.

    thanx a lot! Did not know about this function.

  5. #5
    Registered User
    Join Date
    12-18-2012
    Location
    Tilburg, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: adding a worksheet with a pre-specified private sub.

    Could you perhaps give a small example, because I cannot get it to work. I tried the following into the ThisWorkbook excel object. Thanks again for looking at it

    Please Login or Register  to view this content.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: adding a worksheet with a pre-specified private sub.

    The event is Workbook_SheetChange, to access it double click ThisWorkbook in the Project Explorer, select Workbook from the left dropdown and SheetChange from the right dropdown.

    You'll now see this, which is where the code should go.
    Please Login or Register  to view this content.
    Sh is the worksheet that has been changed and Target is the range on that worksheet that has changed.

    Now I'm not sure what the code you posted is meant to do but perhaps this will work.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-18-2012
    Location
    Tilburg, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: adding a worksheet with a pre-specified private sub.

    Works perfectly. The code I putted in did not really matter, key was that I got the the workbook change function to work. Thanks again!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1