+ Reply to Thread
Results 1 to 11 of 11

Creating a new sheet with each new line item

  1. #1
    Registered User
    Join Date
    11-22-2021
    Location
    Huron Township, Michigan
    MS-Off Ver
    365
    Posts
    32

    Creating a new sheet with each new line item

    I have a workbook that has a template for blanks and a template for coils. I have a table of contents page which is where the data entry begins. What I would like is to make an entry on the table of contents page. In this case, starting with row 4. I would put coil or blank in a column. This would determine which template to use. The next column is for safety. If the answer is Yes, I would like to add the note shown on the Example sheet in cell H1. The next column is for the part number. I would like for the part number to automatically go into cell C3 and then have the new sheet be named whatever is in c3. There has to be a new sheet for every part number using either the coil or blank template. The sheet needs to be named by the part number and safety critical items need to be identified on the sheet. The goal is for all of this to happen automatically when adding a new line on the table of contents page. Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Creating a new sheet with each new line item

    1) Copy this code.
    2) Right-Click the sheet tab "Table of contents"
    3) Select "View Code"
    4) Paste the code into the window that appears.
    5) Save the file as a macro-enabled .xlsm file.
    6) Make changes as needed

    The attached has the code already in it, so you can try it out...

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    11-22-2021
    Location
    Huron Township, Michigan
    MS-Off Ver
    365
    Posts
    32

    Re: Creating a new sheet with each new line item

    I tried copying the code and I got an error message.

    Capture.JPG

  4. #4
    Registered User
    Join Date
    11-22-2021
    Location
    Huron Township, Michigan
    MS-Off Ver
    365
    Posts
    32

    Re: Creating a new sheet with each new line item

    I hadn't been able to open the file and run the one that you sent, but I was able to finally do that. It works! Thank you. I was wondering though, and maybe this is too much, but if it could also change the cell on the template for part number C3 to the new part number - the same one as the tab is named as. Maybe that's too much. I don't know, but is it possible to add that layer?

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Creating a new sheet with each new line item

    Sure - just add the line
    Please Login or Register  to view this content.
    After the line

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-22-2021
    Location
    Huron Township, Michigan
    MS-Off Ver
    365
    Posts
    32

    Re: Creating a new sheet with each new line item

    Thank you so much for your help! But now, I have one more additional question...
    Is there a way to add the safety critical note after the fact. For example, If someone adds the line on the table of contents page, but then doesn't put the yes or no in the safety critical column right at the beginning, but then goes back to that later and puts "yes" for safety critical, is it possible to have the note show up on the tab that had been created already? One of my work colleagues is asking the question as I was super happy with it. If it is not possible, then that will just have to be a manual entry. Just figured I'd ask.

    Again, thank you so much for the help you've given so far!

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Creating a new sheet with each new line item

    Try it like this.....

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-22-2021
    Location
    Huron Township, Michigan
    MS-Off Ver
    365
    Posts
    32

    Re: Creating a new sheet with each new line item

    It works great as originally requested, but it won't add the safety critical after the fact. If you skip that column, create the new sheet, then go back and choose "Yes" to safety critical, it won't add the safety critical statement. It only works if you choose it before creating the sheet.

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Creating a new sheet with each new line item

    For the row where you are adding "Yes" to column B: both A and C need to be filled, and the entry in C needs to match a sheet name.

    (Your workbook also needs at least 5 worksheets in it - which is how many you had in your initial file, but that is only an issue for adding sheets.)

    Oh - and make sure that the code is in the codemodule of the sheet where you are entering "Yes"

    1) Copy the code.
    2) Right-Click the sheet tab where you enter "Yes" in column B
    3) Select "View Code"
    4) Paste the code into the window that appears.
    5) Save the file as a macro-enabled .xlsm file.

    And make sure that events are enabled - run this macro to be sure:

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 03-22-2024 at 04:06 PM.

  10. #10
    Registered User
    Join Date
    11-22-2021
    Location
    Huron Township, Michigan
    MS-Off Ver
    365
    Posts
    32

    Re: Creating a new sheet with each new line item

    Forgive me for my ignorance... where in the code to I add the additional code? Does it go at the end of the code you already gave or does it go somewhere in the middle of it?

    Thank you so much for the time you have given on this!

  11. #11
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Creating a new sheet with each new line item

    That code goes into a standard codemodule, and you can run it by having your cursor within the text of the macro and pressing F5. Then go out to your workbook and change a value in column B to Yes and the corresponding sheet should get the red warning at the top.

    The attached works for me - I added a sheet that lacks the warning, so enter Yes into cell B4 on Table of Contents and the warning should appear on Proof of Code.
    Attached Files Attached Files

+ 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. [SOLVED] Vba to match item description and copy/paste item code to other sheet
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2017, 11:29 AM
  2. VBA code to copy line items from form - overriding previous line item
    By dkostyan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-30-2016, 11:19 AM
  3. [SOLVED] Formula needed - line item of unique item matching criteria
    By NS4Excel in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 04-18-2015, 06:32 PM
  4. Replies: 1
    Last Post: 10-09-2013, 11:44 AM
  5. Replies: 3
    Last Post: 09-03-2013, 10:02 PM
  6. creating a macro to use cell content as subject line in sending email - protected sheet
    By John Eathorne in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-18-2013, 05:06 PM
  7. Combining multiple line items into one line item based on column.
    By mguz018 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-20-2012, 07:22 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