+ Reply to Thread
Results 1 to 9 of 9

VBA to choose template, fill it in and then save workbook - impossible??????

  1. #1
    Registered User
    Join Date
    03-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    39

    VBA to choose template, fill it in and then save workbook - impossible??????

    Hi all,
    I have spent around a month trying to find an appropriate solution to the task below but it’s been to no avail.

    Background:
    I have a workbook called ‘Data Sheet’ which contains a list of employee names (120+), which shift pattern they work, their managers names and individual stats based on their performance in a given quarter. I have spent a lot of time working on this so that these stats are pulled from various different sources rather than manually keyed – Progress!

    At the end of the quarter every manager needs to create a workbook with a 2 sheet performance review for each of their employees. (i.e. 100 employees with 10 managers would result in 10 workbooks being created with 20 sheets in each). This process is currently manual and very time consuming.

    To complicate things further, depending on what shift the employee works (D,R or DP) one of three different templates are needed.


    Task:
    I would like to have some VBA that does the following:
    • Look to see how many employees in the ‘Data Sheet’ are managed by a particular manager.
    • Of those employees, look to see if their shift is “D”, “R” or “DP”.
    • Create a new workbook and copy the correct 2 page template (based on their shift) into it for each employee managed by that manager.
    • Rename the first page of each template to the employee name.
    • Rename the second name of each template to the employee name + “Disc”.
    • Fill in each template using the relevant employees data contained in the ‘Data Sheet’ workbook.
    • Save the work book as the manager name.
    • Do the same for the next manager and so on.


    I know this is a big task but I would really appreciate someone’s genius on this.

    I have tried a lot of different coding and it’s now got to a point where I’m out of ideas and need to start again.

    Thank you.

    ps: I'm unable to upload any examples at the moment.

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: VBA to choose template, fill it in and then save workbook - impossible??????

    Hello and welcome to the forum. All the tasks you have noted are possible to code with loops, but that's not the problem that I see. If you are fortunate then one of the members will have some time to code all of this (and test it). If this thread goes cold, then I would advise you to start new threads with small bite sized problem and increment until you finish your project. And of course, there is little change of help with a dummy workbook.

    Good luck.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA to choose template, fill it in and then save workbook - impossible??????

    Post up your sample source workbook with the templates in it (sanitize the data to generic content, leave the layout alone), then post a sample "results" workbook for one manager and one or two of his him employees. We'll take a look from there.

    Click GO ADVANCED and use the paperclip icon to post up a copy of your workbook.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    03-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: VBA to choose template, fill it in and then save workbook - impossible??????

    Hi abousetta and JBeaucaire,
    Thanks for getting back to me so quick.

    I have attached a simpler version of my data sheet, templates and results as a lot of data is being pulled.
    However, I have not amended the formatting as requested.

    Thank you so much for your help.
    Attached Files Attached Files
    Last edited by dm@stams; 03-03-2012 at 03:51 PM. Reason: Spelling mistakes

  5. #5
    Registered User
    Join Date
    03-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: VBA to choose template, fill it in and then save workbook - impossible??????

    Hi JBeaucaire,
    I have just been looking at your 'Data into template' code and it looks very close to what I am trying to achieve.
    Would I be able to incorporate this along with additional if statements?
    Or am I going down the wrong route?

    Thanks.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA to choose template, fill it in and then save workbook - impossible??????

    That is there for the specific purpose you've found... to serve as a "beginning" for putting a row-based dataset into a standard template. So I would encourage you to try and adapt that very macro... yes, adding more "action" code to do more than the original sample. Build on it.

  7. #7
    Registered User
    Join Date
    03-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: VBA to choose template, fill it in and then save workbook - impossible??????

    I had seen and attempted to modify your coding previously but was overwhelmed by the task I am trying to complete. Thanks to your very clear coding I was able to create a template for every employee within the 'data sheet' very quickly.

    However, I would appreciate some advice as I cannot decide the best way to choose a template? Do I write code to complete the tasks listed in my original post (in order) or is there a simplier way. I am very much a novice when it comes to VBA and I know you guys are consistently hounded with requests/queries but if you could point me in the right direction that would be a great help.

  8. #8
    Registered User
    Join Date
    03-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: VBA to choose template, fill it in and then save workbook - impossible??????

    I have now managed to adapt coding to select the correct template.
    I decided to autofilter the 'data sheet' for each manager so that when I finish the project, I can just loop through each autofilter sub and then run the 'fill in template'.

    How can I adapt the code below to only take action if the row it's working on is not hidden via the autofilter?


    Please Login or Register  to view this content.

    Many thanks.
    Last edited by dm@stams; 03-04-2012 at 11:35 AM. Reason: Code wrap

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA to choose template, fill it in and then save workbook - impossible??????

    If you have applied a filter, then you can set a RNG variable for the remaining visible row. Then you can cycle through the "cells" in the RNG and use the cell.row:

    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)

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