+ Reply to Thread
Results 1 to 14 of 14

Excel 2007 : Copying from multiple templates based on criteria.

  1. #1
    Registered User
    Join Date
    11-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    14

    Copying from multiple templates based on criteria.

    I have a summary page where you enter item numbers followed by the item name. I have a worksheet used as a template which I named template >.<. I have a command button that when pressed will make a new sheet copied from the template and name the sheet according to the item. My question is, how can I modify this code to copy from different templates based on criteria that I input next to the item. Say I have Item 1 in A1, Item Name in A2 and Item type in A3. Right now the macro will name the worksheet depending on A2 but will just copy the template worksheet. One more thing, how do I change this code so that I can copy from hidden worksheets? I'm new here so I hope I posted this right.

    Please Login or Register  to view this content.
    Last edited by Pololuck; 11-29-2011 at 11:32 AM.

  2. #2
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Copying from multiple templates based on criteria.

    i'd suggest declaring a worksheet variable for ease of use:

    Please Login or Register  to view this content.
    then to point that variable to the right template use this line below (i can't tell which sheet contains the selection - for the purpose of this answer i will assume it's in a sheet named "Summary" and the template selection is sitting in cell a3 of that sheet)

    Please Login or Register  to view this content.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    11-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Copying from multiple templates based on criteria.

    I just started using excel about 3 months ago, if I attach the workbook, do you think you can rewrite the code? I have no idea how to write code, I copied that code from a forum . Thank you for the quick reply though.

  4. #4
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Copying from multiple templates based on criteria.

    sure, i suppose. attach away

  5. #5
    Registered User
    Join Date
    11-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Copying from multiple templates based on criteria.

    Here is the attached workbook. If I hide the template it won't copy.
    Attached Files Attached Files

  6. #6
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Copying from multiple templates based on criteria.

    Only change (other than setting your start row to 4) was the following line -- I used this in place of the call to "Template" you had in the attached sheet.

    Please Login or Register  to view this content.
    As long as the C column contains the template name, this will work for you.

    SOlution attached.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    11-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Copying from multiple templates based on criteria.

    Thank you thank you, one more question though. What do I change for it to copy from these templates if they are hidden?

  8. #8
    Registered User
    Join Date
    11-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Copying from multiple templates based on criteria.

    I saw this code in a forum but how would I apply it to my workbook?

    Please Login or Register  to view this content.

  9. #9
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Copying from multiple templates based on criteria.

    Easiest thing to do was just to unhide all the sheets, run the code, then rehide the templates..

    The macro in the attached sheet will do this. Try it out.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    11-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Copying from multiple templates based on criteria.

    I get a compile error, variable not defined and it points to the i in
    [code]
    For i = 1 To ThisWorkbook.Worksheets.Count
    ThisWorkbook.Worksheets(i).Visible = True
    Next i[code]

  11. #11
    Registered User
    Join Date
    11-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Copying from multiple templates based on criteria.

    Sorry about last post, I dont know what happened
    Please Login or Register  to view this content.

  12. #12
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Copying from multiple templates based on criteria.

    huh, how the heck did that happen...possibly uploaded the wrong sheet. Here's the fix (there was no declaration for the 'i' variable).

    Please Login or Register  to view this content.
    That last declaration clears things up....attached is corrected sheet.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    11-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Copying from multiple templates based on criteria.

    Thank you for your time. I appreciate all the help you've given me.

  14. #14
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Copying from multiple templates based on criteria.

    you are welcome, please mark the post as solved.

    ---edit---
    ha ha, you already marked it! my mistake
    Last edited by GeneralDisarray; 11-29-2011 at 11:35 AM.

+ 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