+ Reply to Thread
Results 1 to 8 of 8

Creating multiple workbooks out of 1 workbook based on column values

  1. #1
    Registered User
    Join Date
    10-02-2015
    Location
    Netherlands
    MS-Off Ver
    2010
    Posts
    20

    Creating multiple workbooks out of 1 workbook based on column values

    Hi excel wizzards

    I have only limitted experience with VBA. I've tried some code i've found online, but I dont fully get what to alter to make it work for my particular example.

    I have 1 workbook with 1 sheet that I want to split this into multiple workbooks based on a column.
    Example attached.
    I would like to create seperate workbooks that contain the data for every unique country (column C). So e.g. a file called NLD.xlsx containing only the data for rows for NLD, a file called FRA.xlsx containing only the data for rows for FRA, etc).
    Each file should also have the first 5 rows of general information and the headers.

    Anyone that could point me to a thread containing code I could use? I found some, but these are based on a column containing specific values and i dont know which country names may be included in column C.
    So I think I need to create a collection containng the unique country values and loop through those by filtering the data, but I'm not sure how.

    (I will eventually want to create a seperate xlsm that has a button to push, which will allow to select a source file to load that then will be split, but I think i should be able to find code for that piece).

    Apprieciate any help!
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    10-02-2015
    Location
    Netherlands
    MS-Off Ver
    2010
    Posts
    20

    Re: Creating multiple workbooks out of 1 workbook based on column values

    I've managed to adapt some code that now sort of works, but
    - only copies over 1 row, instead of all of them (assume this lis linked to the 'res' Range?)
    - creates a file for the column header (TR_Country.xlsx) which I dont need
    - not able to get the first 5 rows of general information in each file.

    Code:

    Please Login or Register  to view this content.
    Last edited by Sirilias; 08-15-2018 at 05:49 PM.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Creating multiple workbooks out of 1 workbook based on column values

    Try
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-02-2015
    Location
    Netherlands
    MS-Off Ver
    2010
    Posts
    20

    Re: Creating multiple workbooks out of 1 workbook based on column values

    You, good sir, are a hero. Works like a charm.

    Could you explain a little to me what the code is doing, because this is deffintily a step further than what I started with. Perhaps add some guidance text? Just so I know how to change it for different scenario's.
    E.g.
    - If I dont know the sourcesheet's name in advance, I believe I can update 'With Sheets("blad1")' to 'With Sheets (2)' right? (this seems to work in any case).
    - If the Country values, would be in a different column (not c), how would I update the code? I've tried updating "a = .Columns("c").Value" to another column, which still creates correct file name, but they are without data.
    - If the precedeing general section would fo example be larger and table would start in row 8 (not 6), how would I need to update the code in that case?

    Thank you so much for helping me out!

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Creating multiple workbooks out of 1 workbook based on column values

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-02-2015
    Location
    Netherlands
    MS-Off Ver
    2010
    Posts
    20

    Re: Creating multiple workbooks out of 1 workbook based on column values

    Hi

    I now have a data set that does not have the empty row. so all first 5 rows have something in it.
    The rest is the same, with the header row still being ow six. Is there a way to change the above code for this situation? perhaps adding an empty row and taking it back out before saving?

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Creating multiple workbooks out of 1 workbook based on column values

    Quote Originally Posted by Sirilias View Post
    perhaps adding an empty row and taking it back out before saving?
    Correct,
    Please Login or Register  to view this content.
    and delete at the end
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-02-2015
    Location
    Netherlands
    MS-Off Ver
    2010
    Posts
    20

    Re: Creating multiple workbooks out of 1 workbook based on column values

    Hi Jindon,

    Perfect. I made an additional edit to also get the output to not have the empty row, works perfectly!
    Thanks so much!

    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. Creating Multiple workbooks with different names from a single workbook
    By fsse in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-06-2017, 07:45 AM
  2. Copy Paste Values from multiple workbooks to multiple sheets in one workbook
    By tatendamark in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-12-2017, 09:54 AM
  3. Having problems updating a workbook based on values from many other workbooks
    By gibson2503 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-19-2013, 03:50 PM
  4. Creating a Macro that Imports data from multiple workbooks into one Main workbook
    By MacroHelp911 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2013, 11:03 AM
  5. Creating a searchable "master" excell workbook based on multiple other workbooks
    By mikej_88 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2013, 05:21 PM
  6. [SOLVED] Return multiple values from another workbook, based on Column Headers in other workbook
    By GoGators in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-17-2013, 02:11 PM
  7. Creating multiple workbooks from summary workbook
    By encise in forum Excel General
    Replies: 2
    Last Post: 11-02-2005, 07:40 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