+ Reply to Thread
Results 1 to 49 of 49

Splitting out data to create multiple files

  1. #1
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Splitting out data to create multiple files

    HI,

    I have an excel spreadsheet which will have data for lots of accounts.

    I would like a macro which would split out this data automatically to separate files.

    In my example I have three profit centres:
    PC 1
    PC 2
    PC 3

    I would like three files created if possible. I have previously had a macro that did something similar so I am hoping that this can be done.

    One requirement would be that the file is saved based on the account name e.g. "TB PC 1".XLS (TB needs to be editable as there is something exact I need it to be but I am unsure at this stage what it is)

    Can anyone guide me in any way please?

    Paul
    Attached Files Attached Files
    Last edited by pauldaddyadams; 07-01-2018 at 12:26 PM.

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    TB needs to be editable
    Editable in the macro or an input mesage to the user ???
    - Battle without fear gives no glory - Just try

  3. #3
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Hi,

    Ideally yes. It wouldn't have to be here but this is the preferred choice.

    If its within the script and I know where then that would be ok (I am not very good in VB)

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting out data to create multiple files

    If you really want to save in 1997-2003, we'll have to modify the code - otherwise try:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Hi,

    Code it looking good!

    It doesn't have to be the old version so the code is ok in regards to that - thank you.

    How does it work in terms of where it is where it is saved? Currently I opened the file from my desktop and that's where is has stored the new files.

    Is there any way it can retain the first 1-6 rows?

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting out data to create multiple files

    Sorry about the omission:

    Please Login or Register  to view this content.
    *If you want to save in another place we need to specify the path now coded in red above.

  7. #7
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Thank you for sorting the rows 1-6.

    In regards to the ws.Parent.Path I will come back in regards to this point - I need to know the correct path name

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting out data to create multiple files

    Please Login or Register  to view this content.
    When you get it you can enter it in the red above
    Last edited by xladept; 07-01-2018 at 02:57 PM. Reason: Highlight and Slash

  9. #9
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Hi,

    Your post in number 8, how is that different to 6?

    I notice in the code you have this:
    PC = Array("PC 1", "PC 2", "PC 3")

    In my actual data I have approx. 800 different "PC"s - would I need to list them as this wouldn't be possible. Is there any way to make this dynamic?

  10. #10
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    See next code
    Adjust WkPath if not correct


    Please Login or Register  to view this content.

  11. #11
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Hi,

    I have tried this (attached) and I couldn't get it to work. In the message box its asking for the user to input something - what is this?

    In my example you will see the PCs have different random names.

    The macro would need to either be based on each unique PC number (column C) or PC Name (column D) - Column C would be the preference.
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    In the message box its asking for the user to input something - what is this?

    This the TB to be editable

  13. #13
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Apologies for me not understanding - what should I put in this would it be column C so a "c"?

  14. #14
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    No enter TB or something else you want

  15. #15
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    If you want to change the column where the Profit Center is change
    Please Login or Register  to view this content.
    If you want to change where is the header row change

    Please Login or Register  to view this content.

  16. #16
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689
    Quote Originally Posted by PCI View Post
    No enter TB or something else you want
    In my example file I have 3 unique PC numbers or 3 unique PC names? What would I have to enter specifically as I’m struggling to understand?

    Would I have to list all the names of each unique reference as this could take sometime in my actual data as I have 800+ and I’d be bound to make an error.

  17. #17
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    Would I have to list all the names of each unique reference
    => NO

    Just make a run entering TB and see what's happen ... you will understand

  18. #18
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    It may have a confusion between "PC Name" and "Profit Centre"
    => Adjust

    Please Login or Register  to view this content.

  19. #19
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    as I have 800+

    So you may have also a long time treatment, we may see after, but this due because there is some files manipulations ...!

  20. #20
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting out data to create multiple files

    You're welcome and thanks for the rep!

    The difference between those posts was that I added a string variable for the path and corrected the slash to a backslash.

    It looks now though as PCI is taking good care of you.

  21. #21
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting out data to create multiple files

    Here's a version with unlimited profit centers using the dictionary like PCI has done:

    Please Login or Register  to view this content.
    Last edited by xladept; 07-01-2018 at 09:09 PM.

  22. #22
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    @xladept Thank you for sending the code in post #21. Can I ask please, which column it is based on, at each change in column C or D?

    @PCI, In the message box I have entered "TB", "C", "PC Name", "Profit Centre" and more but each time I get error 400.

  23. #23
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    @PCI, In the message box I have entered "TB", "C", "PC Name", "Profit Centre" and more but each time I get error 400.
    Just put TB
    Is there a statement shown when there is the error 400
    See attached you file with the macro
    Attached Files Attached Files

  24. #24
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Hi

    The requirement for the file name would be name would be:
    Profit Center Number-TrialBalance-Period (MMYYYY)”

    So this for the first file would be "1012102-Trialbalance-072018"

    Can we include this in the code please?

  25. #25
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Hi, When I run the code with "TB" in the message box I get an error 53 with this section highlighted in the code "Kill WkFN ' TO REMOVE the FILE"

  26. #26
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    Clear
    New Macro
    Please Login or Register  to view this content.

  27. #27
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Hi,

    That works when I enter the "TB" in the message box - why do i need to do this out of interest?

    Is this code working on each new instance of column C or D currently as it needs to be C please.

    The file name needs tweaking e.g. currently its "TB 1060100", it would need to be "1060100-Trialbalance-072018" if possible please?

  28. #28
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    That works when I enter the "TB" in the message box - why do i need to do this out of interest?
    Because in Thread #3 you were suggesting to do it , now we can record it in VBA, up to you to change it inside the code when needed

    Is this code working on each new instance of column C or D currently as it needs to be C please.
    Yes the column in reference is C see

    Please Login or Register  to view this content.
    The file name needs tweaking e.g. currently its "TB 1060100", it would need to be "1060100-Trialbalance-072018" if possible please?
    Yes of course it is possible
    Is "Trialbalance-072018" a constant or something to enter ... like the previous "TB" ...?

  29. #29
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    Try and comment
    Please Login or Register  to view this content.

  30. #30
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Can I remove the requirement please to have the user input anything? I wouldn't know how to adjust the code.

    Where in the code do I need to input the change to the file name so it would be:
    Column C PC number
    The word "Trial Balance"
    the period "072018"

  31. #31
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Our messages crossed!! This is Perfect I believe, just what is needed!!

  32. #32
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    Where in the code do I need to input the change to the file name so it would be:
    Column C PC number
    it is done automùatically.

    Where in the code do I need to input the change to the file name so it would be:
    The word "Trial Balance"
    the period "072018"
    See code
    Please Login or Register  to view this content.

  33. #33
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    Our messages crossed!! This is Perfect I believe, just what is needed!!
    Ouf..!

    So the story is done ...?
    Thx for the rep... enjoy Excel
    PCI

  34. #34
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Potentially - it should be done.... But. I have become aware of a requirement to delete some columns from each file.

    should I post it here or as a new request?

  35. #35
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Hi,

    I am reluctant to post because of the change from the original requirements but I think it can be achieved by amending the current code (and then adding the part to delete columns).

    1. You will see that I no longer have header rows which need to be retained. Only the first row
    2. Column B is now the column to be split (to create each new file)
    3. Columns A:E need to be deleted (so I am left with just three columns as shown on the tab TB load Format)

    Can you help out again please, sorry!
    Attached Files Attached Files

  36. #36
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    Please open a new thread and make reference to this one: Thread title is important because it is used as key to search information.
    Now we don nor split anymore

  37. #37
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting out data to create multiple files

    Still the way to work ???:
    Save in the same folder as the orginal file
    Save with same format
    File name as seen before

  38. #38
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Quote Originally Posted by PCI View Post
    Still the way to work ???:
    Save in the same folder as the orginal file
    Save with same format
    File name as seen before
    I dont understand!?!? I opened up a new thread with the requirements.

  39. #39
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting out data to create multiple files

    Field:=4 means column D as does ws.Cells(n, 4)

    Please Login or Register  to view this content.
    Last edited by xladept; 07-02-2018 at 12:05 PM.

  40. #40
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Is there a way to amend this part:
    Please Login or Register  to view this content.
    As the 1060100 was just an example. It would have to be based on the cell value which I think its doing at the end. e.g.

    This: 1060100-Trialbalance-072018 310030.XLSX

    Needs to be: 310030-TrialBalance-072018

  41. #41
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Do I now need to change this:
    Please Login or Register  to view this content.
    to 1?

    Lastly - is there anyway to then delete columns A:D?
    Attached Files Attached Files

  42. #42
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting out data to create multiple files

    Just put 310030-TrialBalance-072018 inside those quotes or designate a field on the sheet for that value. The n is for the first row of data in that line.

    To delete Columns 1-4:

    Please Login or Register  to view this content.
    *If you have a differently organized sample - please post it.
    Last edited by xladept; 07-02-2018 at 01:34 PM.

  43. #43
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Hi, I wouldn’t want the first part to be fixed though. The first digits need to be automatically populated based on the PC number column

  44. #44
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Hi,

    I changed the code to this:
    Please Login or Register  to view this content.
    And its almost working perfectly. How do I change this:
    Please Login or Register  to view this content.
    So the PC appears ahead of the "-TrialBalance-072018"?
    Attached Files Attached Files
    Last edited by pauldaddyadams; 07-02-2018 at 01:59 PM.

  45. #45
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting out data to create multiple files

    Just put BN = K(n) & " " & TB & ".XLSX"

  46. #46
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    Hi, The file name is now working as it should however having checked the files the data isnt being pulled correctly.

    I have another macro to compare to. When I run this I have 5 files and with the splitter (renamed to this from pauldaddyadams) it produces 6 as there is a file created for the header row which it shouldnt create.

    The data in the files is also duplicated - it isn't pulling the data for that PC number only.

    Any ideas why?
    Attached Files Attached Files

  47. #47
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting out data to create multiple files

    How about:

    Please Login or Register  to view this content.
    Last edited by xladept; 07-02-2018 at 03:55 PM. Reason: Correction Offset & Fillter Field

  48. #48
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Splitting out data to create multiple files

    I think we are there!!!!

    I am going to test tomorrow by uploading into the system but i think we have achieved what we need to!!

    Thank you so much for helping on this!
    Last edited by pauldaddyadams; 07-02-2018 at 04:14 PM.

  49. #49
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting out data to create multiple files

    You're welcome! But it shouldn't take hours

+ 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. Splitting excel data (.xls) into multiple files (.xls)
    By marcus74 in forum Excel General
    Replies: 1
    Last Post: 09-27-2017, 08:05 AM
  2. Splitting out Excel data to multiple files based on one column values
    By MetroBOS in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-04-2015, 04:54 PM
  3. Splitting out Excel data to multiple files based on one column's values
    By MetroBOS in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2015, 11:38 AM
  4. How to create multiple word documents using data from multiple excel files.
    By Milan Kotus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-14-2013, 12:07 PM
  5. How do I combine splitting data into files then splitting the new files data into multiple
    By Lauraguthrie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-01-2013, 01:18 PM
  6. Splitting out Excel data to multiple files based on one column's values
    By machos in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2011, 08:55 AM
  7. Splitting txt file into multiple txt files
    By undergraduate in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2010, 11:32 AM

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