+ Reply to Thread
Results 1 to 8 of 8

VBA for generating new WS based on criteria and copying info into it

  1. #1
    Registered User
    Join Date
    01-23-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    58

    VBA for generating new WS based on criteria and copying info into it

    Hi
    I need to build a macro that will do the following:
    1.For every unique value in columnA generate a new worksheet.
    2. Name of the new worksheet should be equal to the unique value.
    3. Write "" in known cells in the new worksheet. (certain cells will need to formatted - such as borders etc) but the cell to manipulate will always remain same.
    4. Copy values from other cells (or columns) in the same row (as that of the unique value) into known cells on the new worksheet created.
    5. Move on to the next unique value and repeat.

    Any idea how this can be done in excel 2007?

  2. #2
    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 for generating new WS based on criteria and copying info into it

    Here's my stock macro for this task. It gets unique values from column A, grabs all the rows with matching values and puts them onto a new sheet named for the unique value. It sorts the sheets alphabetically. It creates the sheets as needed.
    Please Login or Register  to view this content.
    _________________
    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!)

  3. #3
    Registered User
    Join Date
    01-23-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: VBA for generating new WS based on criteria and copying info into it

    Thanks JBeauCaire - What do I need to do if I want to ignore the first two rows of column A? This may be a stupid question but I am not a programmer! - although I do like to automate stuff to make my life easier
    Appreciate your help!

  4. #4
    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 for generating new WS based on criteria and copying info into it

    For a filter command to work, we do need at least one "title" cell at the top. You're saying that you actually have two?

    The code section "get a temporary list of unique values" is copy all of column A to column EE. If the resulting list in EE includes a value in E2 you want excluded (we have to leave E1 in as a "header"), then let's just delete that cell before proceeding. Edit this section:
    Please Login or Register  to view this content.
    If this doesn't help, post up a usable example workbook so we can look at the problem directly together.

    Click GO ADVANCED and use the paperclip icon to post up your workbook.

  5. #5
    Registered User
    Join Date
    12-13-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Post [SOLVED] Re: VBA for generating new WS based on criteria and copying info into it

    I have a similar problem, any chance you can help me with this?

    I can create the tabs and copy report columns to each tab with the code below. What I'm trying to do is instead of copying the columns, I'd like to copy a worksheet named "Sample" and populate each report with the same format I have in that "Sample" worksheet. Any help is appreciated...



    Please Login or Register  to view this content.
    Last edited by d-zein; 12-13-2010 at 07:43 PM. Reason: Solved

  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 for generating new WS based on criteria and copying info into it

    'FILL OUT A TEMPLATE FROM A DATABASE
    I have a macro for taking the data from a database and filling out a template sheet over and over again with the data.The macro fills out the template and saves each one as a separate file, but that last part can be tweaked to do other things, this is mainly to demonstrate a simple way to fill out a form from a row-based database.

    The technique is complete, you should be able to adapt it to your scenario.

  7. #7
    Registered User
    Join Date
    12-13-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: VBA for generating new WS based on criteria and copying info into it

    Holly Cow Batman! This works great Jerry! Thanks a lot.

  8. #8
    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 for generating new WS based on criteria and copying info into it

    Glad to help.

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ 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