+ Reply to Thread
Results 1 to 8 of 8

Code to place code into newly created sheets???

  1. #1
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    Code to place code into newly created sheets???

    I have a routine that creates a new sheet when a new teacher is brought in.

    I need to create code for the Change event in that sheet's object (Not sure if I am using the word "object" correctly, I mean to refer to the "module" in the sheet collection where vba is placed for that sheet specifically!).

    The code I need to place is "cookie cutter" - no changes, a simple copy and paste will achieve what I need.

    I would like to learn how this is done - can anyone give me a good shove in the right direction?

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Code to place code into newly created sheets???

    http://www.cpearson.com/excel/Events.aspx
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

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

    Re: Code to place code into newly created sheets???

    Could you not use the workbook level event SheetChange?
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    Re: Code to place code into newly created sheets???

    Big UHG. Problem in the translation.

    When I create a new sheet I need to place code I have written into that new sheet's module into it's Change event - like:
    1) New sheet created
    2) Copy code from where-ever
    3) Open code sheet for new sheet
    4) Paste cod block, a sub-routine, into the change event of that new sheet

    Am I getting my point across? How about just plain old "How can I write code into a new sheet's module?

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

    Re: Code to place code into newly created sheets???

    The site that Solus has posted a link for shows you how to write event code using code here.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Code to place code into newly created sheets???

    Why not just copy an existing sheet that already has the code?
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    Re: Code to place code into newly created sheets???

    @ Norie - Thank-you for never giving up on me. The link looks like it might be exactly what I have been trying to remember!

    @ shg - Excellent alternative.
    The reason is that when I was waist deep into Excel about ten years ago I knew how to create a module that woule replace and/or update code in other areas. If I can not do this or find out how that was done, I can go along as you suggest which would involve:

    Copy a sheet
    Rename that sheet
    Wipe that sheet clean

    So far, that does not appear to be a problem!
    If my search for code to copy code fails, you have given me a working alternative; Thank-you!
    Last edited by brucemc777; 03-29-2014 at 11:52 AM.

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

    Re: Code to place code into newly created sheets???

    If you want to apply the same event code to multiple sheets you can use the SheetChange workbook event.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 07-16-2013, 01:20 PM
  2. VBA: format newly created sheets as text
    By maria.blue44 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-04-2013, 09:13 PM
  3. [SOLVED] Code not working on newly created workbooks.
    By dwhite30518 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 05-21-2012, 02:04 PM
  4. Using a macro to add code to a newly created workbook.
    By Alagard in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-16-2010, 06:08 PM
  5. Newly Created Sheets Replacing Existing
    By degmania in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-20-2008, 04:04 PM

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