+ Reply to Thread
Results 1 to 41 of 41

Split and Save as a seprate excel file. How to do it?

Hybrid View

simplyxl Split and Save as a seprate... 06-02-2013, 06:45 AM
simplyxl Re: Split and Save as a... 06-02-2013, 02:25 PM
jaslake Re: Split and Save as a... 06-02-2013, 03:28 PM
simplyxl Re: Split and Save as a... 06-02-2013, 03:51 PM
jaslake Re: Split and Save as a... 06-02-2013, 04:21 PM
simplyxl Re: Split and Save as a... 06-03-2013, 04:26 AM
jaslake Re: Split and Save as a... 06-03-2013, 03:29 PM
simplyxl Re: Split and Save as a... 06-03-2013, 03:42 PM
jaslake Re: Split and Save as a... 06-03-2013, 04:22 PM
simplyxl Re: Split and Save as a... 06-03-2013, 03:50 PM
jaslake Re: Split and Save as a... 06-03-2013, 04:12 PM
simplyxl Re: Split and Save as a... 06-03-2013, 04:21 PM
jaslake Re: Split and Save as a... 06-03-2013, 04:28 PM
simplyxl Re: Split and Save as a... 06-03-2013, 04:26 PM
simplyxl Re: Split and Save as a... 06-03-2013, 04:35 PM
jaslake Re: Split and Save as a... 06-03-2013, 04:55 PM
simplyxl Re: Split and Save as a... 06-03-2013, 05:02 PM
jaslake Re: Split and Save as a... 06-03-2013, 05:07 PM
jaslake Re: Split and Save as a... 06-03-2013, 05:15 PM
simplyxl Re: Split and Save as a... 06-03-2013, 05:12 PM
simplyxl Re: Split and Save as a... 06-04-2013, 01:28 AM
jaslake Re: Split and Save as a... 06-04-2013, 11:01 AM
simplyxl Re: Split and Save as a... 06-04-2013, 11:13 AM
jaslake Re: Split and Save as a... 06-04-2013, 12:48 PM
simplyxl Re: Split and Save as a... 06-04-2013, 01:44 PM
jaslake Re: Split and Save as a... 06-04-2013, 03:48 PM
simplyxl Re: Split and Save as a... 06-04-2013, 04:02 PM
jaslake Re: Split and Save as a... 06-04-2013, 04:12 PM
simplyxl Re: Split and Save as a... 06-04-2013, 04:16 PM
jaslake Re: Split and Save as a... 06-04-2013, 04:23 PM
simplyxl Re: Split and Save as a... 06-04-2013, 04:30 PM
jaslake Re: Split and Save as a... 06-04-2013, 04:38 PM
simplyxl Re: Split and Save as a... 06-04-2013, 06:12 PM
jaslake Re: Split and Save as a... 06-04-2013, 06:38 PM
simplyxl Re: Split and Save as a... 06-05-2013, 01:39 AM
jaslake Re: Split and Save as a... 06-05-2013, 08:20 AM
simplyxl Re: Split and Save as a... 06-05-2013, 09:19 AM
jaslake Re: Split and Save as a... 06-05-2013, 09:39 AM
simplyxl Re: Split and Save as a... 06-05-2013, 10:23 AM
jaslake Re: Split and Save as a... 06-05-2013, 12:12 PM
simplyxl Re: Split and Save as a... 06-05-2013, 01:01 PM
  1. #1
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Split and Save as a seprate excel file. How to do it?

    I have a slight problem. Got a sales report recently and it will now be a daily visitor to my mailbox, and will go out as well.....

    I need to rename the report like "Daily Sales Stats - Financial Year - 2013-2014 - (Input Current Days Date).
    Delete 12 tabs out of 16 and send the remaining 4

    Is it possible to do this through a VBA code or something? If yes, could someone be kind to help me with code. I found one here

    http://www.extendoffice.com/document...-workbook.html

    but it separates each tab whereas I want to keep the original report as is, but create another fresh report with the desired 4 tabs,.

    Thank you all the experts...

  2. #2
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Just struck me – I should have provided the sheet names that I want to include. They are East, West, North and South. They have the data for all the sales team. I want to extract these tabs and send them daily.

    Once again: My book has 16 worksheets 12 are named by month (Jan/Feb/March…Dec). The other 4 are East, West, North and South. I want to create a separate workbook to include only these 4 sheets.

    Thank you.
    Last edited by simplyxl; 06-02-2013 at 02:31 PM.

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    What you require is rather straight forward. However, for me, I'd want to test the Code before I presented it to you. To do so, I'd need to build a Workbook that emulates what you're working with. You have that workbook. Please sanitize it for proprietary information and share it so I/We don't have to build it.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Hmmm...I do not have the workbook at hand. Can get one in sometime. Currently facing some server issues in the office. The data is getting migrated, unfortunately for me. I will need sometime to get that out to you. Just want to check the number of columns each data sheet has, as I don't want to give you a wrong sample.

    But I am sure that the workbook has 16 tabs and I need only the ones named as East, West, North and South.
    Last edited by simplyxl; 06-02-2013 at 03:58 PM.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    I'd not be concerned re: this
    Just want to check the number of columns each data sheet has
    The Code will figure that out. Post a sample that represents what you have...explain what you want...the Code will do the rest.

  6. #6
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Sorry for late response. Had a lot of internal issues in the morning.

    Per your requirement. Attached:

    1. Book1 dummy data with 16 tabs. East sheet has the explanation
    2. Daily Sales Stats - Financial Year - 2013-2014 - June 3, 2013 is the new report I want to create daily



    My thought is I have provided everything. But let me know if you need more info. Thank you for choosing to help me.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    The Code in the attached appears to do as you describe. Place the attached workbook in the same Folder as the equivalent of your "Book1" workbook. Run from the Button on "Macro Book". The Code will ask you which file (again, the equivalent of "Book 1") you wish to process.

    The Code assumes the Report Date is the same for East, West, North and South. It further assumes that at least one of these four Worksheets is the first Worksheet in the Workbook and it assumes that these four Worksheets exist in the Workbook.

    If Daily Sales Stats - Financial Year - 2013-2014 - June 3, 2013.xlsx already exists the Code will ask if you want to delete it. If you answer Yes, the Workbook is deleted and recreated. If you answer No, the Code terminates.

    This "Stuff" complicated things significantly:

    Create a fresh report with the name as: Daily Sales Stats - Financial Year - 2013-2014 - (Input Date) 2013_6_3 = 6/3/2013
    In column A of the fresh report update the date from Column A of Main Report (Book 1) 2013_6_3 = 6/3/2013
    In column B of the fresh report update the Name from Column A Brad Fred.xls = Brad Fred

    Try it, let me know of issues.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Thanks, but it gives my Run Time Error 9 on
     .Range("A1") = myArray(1) & "/" & myArray(2) & "/" & myArray(0)
    Also can I include this as a module in my existing macro? The report in which I get the data from my office. It is a same type of file so I think it is a macro

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    Let's geter running...then we'll figure out a way to incorporate
    can I include this as a module in my existing macro

  10. #10
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    One thing more I just saw in the report today there were less than 16 tabs only till June. Could that be the issue...

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    No, this is not an issue
    there were less than 16 tabs only till June
    THIS is an issue
    The Code assumes the Report Date is the same for East, West, North and South. It further assumes that at least one of these four Worksheets is the first Worksheet in the Workbook and it assumes that these four Worksheets exist in the Workbook.
    What this Code snippet is doing is parsing out the Date
    .Range("A1") = myArray(1) & "/" & myArray(2) & "/" & myArray(0)
    This error typically means that something does not exist
    Run Time Error 9
    I don't get that error with your sample "Book 1"...so, there apparently is some difference(s) in the Book you actually ran the Code against. If you've not done so, run against "Book 1" and let me know what happens.

    Another thing I'd like you to do...do you know how to set a break point in the Code? Open and use the Immediate Window? If yes, set a break point at that line of Code. Then, open the immediate window and type in ?.range("A1")...what do you see? On your sample Book 1 I see 2013_6_3.

    If you're not familiar with the above process let me know, I'll step you through it.

  12. #12
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Report Date is the same for East, West, North and South - Yes
    It further assumes that at least one of these four Worksheets is the first Worksheet in the Workbook and it assumes that these four Worksheets exist in the Workbook - Yes
    .Range("A1") = myArray(1) & "/" & myArray(2) & "/" & myArray(0) - Okay, but the length of C:\Users\Desktop\Daily Sales Report\2013_6_3 - Robin Hood.xls may vary there may be more \ from time to time


    On Book 1 get run time error 9 on
     cel.Offset(0, 1).Value = Split(cel.Value, "-")(1)
    I see June 3, 2013 on A1


    Sorry but am new to all this.............

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    Have you run the Code on the sample file you posted (Book 1)? Did you get errors?

  14. #14
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Good idea!

    I found a code before posting here on this link: http://www.extendoffice.com/document...-workbook.html

    It was splitting the worksheets into workbooks for me but I want to get the data from the 1 to 4 zones into one workbook with the explanation incorporated in my Book 1 I shared.

    I also see that the number of columns in the 4 (East - South) tabs vary. I am guessing that is not a concern. Though my sample had the same number of columns in each sheet. Is this right?
    Last edited by simplyxl; 06-03-2013 at 04:29 PM.

  15. #15
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Yes, Run time 9 on cel.Offset(0, 1).Value = Split(cel.Value, "-")(1)

    The data for tab 1 gets copied. Report name gets updated. Nothing else.

  16. #16
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    I can't duplicate the error. Please upload the Workbook you're running the Code against. I may have inadvertently modified something.

  17. #17
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Same as post 6. Attached.

    May I also have your permission to sign off for a bit. Got to get on the phone and make some sales.

    My boss is looking a bit concerned
    Attached Files Attached Files

  18. #18
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    May I also have your permission to sign off for a bit
    You don't need my permission!!! Do you job! I'll continue to help as I can! Gotta' admit...at this point, I don't know why it works for me and not for you.

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    Well, now I know why you were getting this error
    Run time 9 on cel.Offset(0, 1).Value = Split(cel.Value, "-")(1)
    In attached Macro Book I've cleared some variables. I don't believe this change was causing an issue...just to be on the safe side.

    Place both these files in the same Folder...don't care where. Run the Code...let me know...

    When it works with Book 2...I'll explain...
    Attached Files Attached Files
    Last edited by jaslake; 06-03-2013 at 05:22 PM.

  20. #20
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Deeply appreciated! May be you can take a look at the link i posted. It may need some of your expertise. It was doing (segregating all the sheets). But may be it may be customized to meet my requirements. I admit have no knowledge of it, just guessing.

    Thanks and will wait for your help and let you know.

    Have a great day...............

  21. #21
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Hi John,

    This works great even with my original data. Apart from one error (point 1).

    Few things that require your expertise further:


    1 - I get an error on this line:

    Range("A1") = myArray(1) & "/" & myArray(2) & "/" & myArray(0)
    This is because I found out that the name of the path was longer in today's version maybe this was created by someone else at a different location. The macro (real data sheet I got). So I tried amending the line as below:

        '.Range("A1") = myArray(1) & "/" & myArray(2) & "/" & myArray(3) & "/" & myArray(4) & "/" & myArray(5) & "/" & myArray(6) & myArray(0)
    But it did not work, as I expected in my current state...

    The original final name in Column A is like this:

     C:\Users\ASRAR\Desktop\Sales Report\Revenue Reports\ FORECASTING - SaleSMC - South Report - Sale Revenue Report - 2013_6_3 - Brad Fred.xls
    Can this be made dynamic?


    2 - Can an auto adjustment to the column widths be added?

    3 - I also understood from your notes that the code assumes that first sheet to be any one of East/West/North/South. So it will not work if these are not. Is it possible to change it so as to copy irrespective of the placement of the sheets?

    4 - Also it doesn’t work when any of the 4 sheets don’t have a data. For instance, the report today did not have data in south sheet. I got a runtime error on

     .Range("A1") = myArray(1) & "/" & myArray(2) & "/" & myArray(0)
    5 - Once this is done, I can run the test again and then we can look into the integration of this as a module into the existing code file that my office sends this collated data in, as you had previously suggested.

    Thank you for the time and expertise!

    Rest all is great!
    Last edited by simplyxl; 06-04-2013 at 09:07 AM.

  22. #22
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    I can make the Code work on records like this
    C:\Users\ASRAR\Desktop\Sales Report\Revenue Reports\ FORECASTING - SaleSMC - South Report - Sale Revenue Report - 2013_6_3 - Brad Fred.xls
    However, unless you standardize your Naming Convention, inevitably you'll be faced with errors.

    A way to reduce the potential for error would be for the User select a Report Date from a popup calendar.

    I'll need to look at these other issues:
    • Can an auto adjustment to the column widths be added? This is already being done...please explain further...
    • Also it doesn’t work when any of the 4 sheets don’t have a data. I'll look at this...it can be fixed.
    • Is it possible to change it so as to copy irrespective of the placement of the sheets? Can be done...will take a bit more Code...if we go with the popup calendar this issue goes away.
    Get back to me...I'll get back to you.

  23. #23
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Good morning sir,

    Popup calendar. - Okay sir

    I'll need to look at these other issues:

    Can an auto adjustment to the column widths be added? This is already being done...please explain further... - Auto fit to contents, else can go with what I have.

    Also it doesnt work when any of the 4 sheets dont have a data. I'll look at this...it can be fixed. - Thank you.

    s it possible to change it so as to copy irrespective of the placement of the sheets? Can be done...will take a bit more Code...if we go with the popup calendar this issue goes away.
    - Perfect, thank you sir.

    Thanks sir.

  24. #24
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    The Code in the attached accommodates these things:
    Popup calendar
    Can an auto adjustment to the column widths be added
    it doesn’t work when any of the 4 sheets don’t have a data
    change it so as to copy irrespective of the placement of the sheets
    Let me know of issues.
    Attached Files Attached Files

  25. #25
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    You are a perfectionist. This is great. I can't believe my eyes. Super stuff!

    My I request for the last one now i.e. what changes would this need so that it can be added as a module within the compiler the team uses.

    Thank you John...really thank you!

  26. #26
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    Tell me the process, step by step...perhaps I can figure it out just from your description but, probably not. I'd really like to see the Workbook (preferably populated with Data) and the Code.

    If this is not possible I can explain how to migrate Macro Book Code and frmCalendar to your compiler workbook but the integration will probably get messy if I can't "see" what's going on.

    How would you want the Macro Book Code to run? As a separate, final step by pushing a button or integrated with the compiler Code with no User interaction?

  27. #27
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Just as a separate final step is all I would like. No integration needed. In the last few days I have learnt a little bit, so don't want to play with the original code. The authorities will screw me if anything goes wrong with what is already there.

    I did beforehand checked with them if I can share the data and code but they denied stating there's a lot of proprietor info in the code itself. I hope you understand the data security issues.

    If I can get a module to add. I can do that.

    Thanks for your help and sorry for my inability to share the preparatory code.
    Hope you will understand sir.

  28. #28
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    I understand
    sorry for my inability to share the preparatory code
    Let me play with it...I'll describe what I believe I would do. This will probably not work the first time around...we may need several runs at it.

  29. #29
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Thank you very much for your understanding.

    Deepely appreciate your help.

  30. #30
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    I'm not certain how I'll approach this yet...
    Will you be able to add a Button in the compiler?
    Will you be able to add a worksheet?
    Can you give me a Cell Address on a worksheet that's ALL mine? If so, I'll need the Sheet Name and the Cell Address

  31. #31
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Will you be able to add a Button in the compiler? - Yes

    Will you be able to add a worksheet? If mandatory "Yes"

    Can you give me a Cell Address on a worksheet that's ALL mine? - in case of new "A1", "A15" in case of existing

    If so, I'll need the Sheet Name and the Cell Address - "Split and Save" in case of new. Old one is I guess Compiler where I want to add a button
    Last edited by simplyxl; 06-04-2013 at 04:32 PM.

  32. #32
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    So, you'll add a Worksheet called "Split and Save". This will be a blank Worksheet except it will have the "Run Me" Button...is this correct?

  33. #33
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Correct. Thanks!

  34. #34
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    EDIT: Upper Right References should be UPPER LEFT but then, I'm sure you figured that out.

    I can't/won't promise this'll work.
    1. Create a new Folder on your Desktop (or anywhere...just know where it is) and call the Folder "Macro Code"
    2. Save the new attached Macro Book With Calendar v2 in this new Folder
    3. Open Macro Book With Calendar v2 and go into VBA (Alt + F11)...you'll see a screen similar to this...make certain Forms, Modules and Class Modules are expanded.
    4. Alt_F11 Screen.jpg
    5. Highlight frmCalendar...click on File (upper right)...click Export File...navigate to the "Macro Book" Folder...click Save
    6. Highlight CreateBookMod...click on File (upper right)...click Export File...you won't have to navigate this time but if you do, navigate to the "Macro Book" Folder...click Save
    7. Highlight mGlodals...click on File (upper right)...click Export File...you won't have to navigate this time but if you do, navigate to the "Macro Book" Folder...click Save
    8. Highlight clsCmdButtons...click on File (upper right)...click Export File...you won't have to navigate this time but if you do, navigate to the "Macro Book" Folder...click Save
    9. Having done this, all the Macro Book Code and UserForm are in your Folder "Macro Code"
    10. Close Macro Book With Calendar v2
    11. IMPORTANT!!! Create a COPY of your Compiler Workbook and open it
    12. Add a Worksheet called "Split and Save". If you CHANGE the Name of this Worksheet the Code will also need changed...this Worksheet is referenced by Name in the Code.
    13. Go into VBA (Alt + F11)...I can't give you a picture because I don't have the File...you'll see a screen similar to the previous jpg except it'll be the compiler project stuff.
    14. Click on File (upper right)...click Import File...navigate to the "Macro Book" Folder...select frmCalendar...click Open
    15. Click on File (upper right)...click Import File...you won't have to navigate this time but if you do, navigate to the "Macro Book" Folder...select CreateBookMod...click Open
    16. Click on File (upper right)...click Import File...you won't have to navigate this time but if you do, navigate to the "Macro Book" Folder...select mGlodals...click Open
    17. Click on File (upper right)...click Import File...you won't have to navigate this time but if you do, navigate to the "Macro Book" Folder...select clsCmdButtons...click Open
    18. Having done this, all the Macro Book Code and UserForm are in your compiler Workbook.
    19. Select the Tab "Split and Save"...add a Forms Control Button to this worksheet...call it what you wish. Assign the Macro Create_Book to this Button.
    As you know, I can't test this process...I performed all the above steps and it appears to work...I'll help as I can, how I can...let me know of issues.

    EDIT: Upper Right References should be UPPER LEFT but then, I'm sure you figured that out.
    Attached Files Attached Files
    Last edited by jaslake; 06-04-2013 at 08:23 PM.

  35. #35
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Thank you for this detailed explanation John.

    I followed all the steps suggested. But on running the Save and Split "Create Work Book" module it is asking me to open another file as was with V1, when I try to open the file it says that the file is already open. Any thoughts...

    I understand you have no access to my original file is posing this, as you were able to run. Maybe we can give it a shot or two else I'll check with the boss if I can share the original file. Sorry for this but its beyond my authority

    Thanks for all the help.
    Last edited by simplyxl; 06-05-2013 at 01:45 AM.

  36. #36
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    Well you've got me confused...where do Sheets East, West, North and South live? Tell me the process, step by step...

  37. #37
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Sorry John if I wasn’t clear. The complete process is outlined below:

    An employee from our company pulls the sales reports by zone
    The (East, West, North, South) reports are then compiled using a compiler that was a macro (and now I know it is…)
    This macro-enabled sheet with zonal data and some more analysis (Pivots, Graphs etc…) is sent to me. The report actually has more than 16 tabs, these were hidden, and got to know only, when I asked if can share the original file
    The 4 tabs are on this exhaustive report. I need to only extract the data from these 4 tabs which have humongous data and send it out as per the sample format report I shared

    So I wanted to integrate the fantastic code you provided into the same macro, but use it as a final step.

    Please do do let me know if you have any questions or if I have not clearly defined the process

    Thank you.

  38. #38
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    I misunderstood...I thought the compiler Code was creating a new Workbook.
    Replace ALL Code in Module CreateNewBook with this Code...let me know of issues.
    Option Explicit
    
    Sub Create_Book()
        Dim myPath As String
        Dim wb1 As Workbook
        Dim vWks As Variant
        Dim NewBook As Workbook
        Dim NewBookName As String
        Dim FileFormatNum As Long
        Dim iReply As Integer
        Dim i As Long
        Dim LR As Long
        Dim vWksLR As Long
        Dim LC As Long
        Dim yourArray As Variant
        Dim Rng As Range
        Dim cel As Range
        Dim ws As Worksheet
    
        Set Rng = Nothing
        Set wb1 = Nothing
        Set NewBook = Nothing
        Set ws = Sheets("Split and Save")
    
        ws.Range("A1").ClearContents
        ws.Range("A1").NumberFormat = "[$-409]mmmm d, yyyy;@"
    
        frmCalendar.Show_Cal
    
        If ws.Range("A1").Value = "" Then
            MsgBox "Please Select Report Date"
            Exit Sub
        End If
    
        NewBookName = "Daily Sales Stats - Financial Year - 2013-2014 - " & ws.Range("A1").Text
        Application.ScreenUpdating = False
        myPath = ThisWorkbook.Path & "\"
    
        If Not FileFolderExists(myPath & NewBookName & ".xlsx") Then
            Application.SheetsInNewWorkbook = 4
            Set NewBook = Workbooks.Add
            With NewBook
                FileFormatNum = 51
                Application.DisplayAlerts = False
                .SaveAs Filename:=myPath & NewBookName, FileFormat:=FileFormatNum
                Application.DisplayAlerts = True
            End With
        Else
            iReply = MsgBox(Prompt:=NewBookName _
                    & Format(Date, "mmmm d, yyyy") & " already exists," & vbCrLf _
                    & "                  Do you wish to Delete the file and Create a new file?", Buttons:=vbYesNoCancel, Title:="WORKBOOK EXISTS")
            If iReply = vbYes Then
                On Error Resume Next
                Kill myPath & NewBookName & ".xlsx"
                On Error GoTo 0
    
                Set NewBook = Nothing
                Application.SheetsInNewWorkbook = 4
                Set NewBook = Workbooks.Add
                With NewBook
                    Application.DisplayAlerts = False
                    FileFormatNum = 51
                    .SaveAs Filename:=myPath & NewBookName, FileFormat:=FileFormatNum
                    Application.DisplayAlerts = True
                End With
            Else
                wb1.Close , False
                Exit Sub
            End If
        End If
    
        i = 1
        With ThisWorkbook
            For Each vWks In Array("East", "West", "North", "South")
                .Sheets(vWks).UsedRange.Copy
    
                vWksLR = .Sheets(vWks).Cells.Find("*", SearchOrder:=xlByRows, _
                        SearchDirection:=xlPrevious).Row
    
    
                With Workbooks(NewBookName & ".xlsx").Sheets("Sheet" & i)
                    .Range("A1").PasteSpecial xlPasteFormats
                    .Range("A1").PasteSpecial xlPasteValues
                    .Range("A1").Value = "Date"
                    .Range("B1").Value = "Sales Report:"
                    If vWksLR > 1 Then
                        LR = .Range("A" & .Rows.Count).End(xlUp).Row
                        LC = .Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
                                SearchDirection:=xlPrevious).Column
                        Set Rng = .Range(.Cells(2, 1), .Cells(LR, 1))
                        'Get and Split out the Sales Report Name
                        For Each cel In Rng
                            yourArray = Split(cel.Value, "-")
                            cel.Offset(0, 1).Value = yourArray(UBound(yourArray))
                            cel.Offset(0, 1).Value = Split(cel.Offset(0, 1).Value, ".")(0)
                        Next cel
                        .Range("A2").Value = ws.Range("A1").Value
                        .Range("A2").Copy .Range("A3:A" & LR)
                        .Columns("A:B").HorizontalAlignment = xlLeft
    
                        Set Rng = Nothing
    
                        Set Rng = .Range(.Cells(1, 1), .Cells(1, LC))
                        With Rng
                            .HorizontalAlignment = xlCenter
                            .Font.Name = "Calibri"
                            .Font.FontStyle = "Bold"
                            .Font.Size = 11
                            .Interior.Pattern = xlSolid
                            .Interior.ThemeColor = xlThemeColorDark2
                        End With
    
                        With .UsedRange.Offset(1, 0).Font
                            .Name = "Calibri"
                            .FontStyle = "Regular"
                            .Size = 11
                        End With
                    End If
                    .Name = vWks
                    .Cells.Columns.AutoFit
                    Application.CutCopyMode = False
                End With
                i = i + 1
            Next vWks
        End With
        Set Rng = Nothing
        Set wb1 = Nothing
        Set NewBook = Nothing
        Application.ScreenUpdating = True
    End Sub
    
    Public Function FileFolderExists(strFullPath As String) As Boolean
    'Author       : Ken Puls (www.excelguru.ca)
    'Macro Purpose: Check if a file or folder exists
    
        On Error GoTo EarlyExit
        If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True
    
    EarlyExit:
        On Error GoTo 0
    
    End Function

  39. #39
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Truly a genius can only do such superlative work!

    My sincere thanks for helping me accomplish this. Would have never been possible otherwise.

    Just wondering if there is also a way to maybe auto run both the codes at a certain time on a daily basis. Not sure if that is possible though.

    Thanks again…

  40. #40
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Split and Save as a seprate excel file. How to do it?

    Hi simplyxl

    You're welcome...glad I could help. Thanks for the Rep.

    This can be done...
    auto run both the codes at a certain time on a daily basis
    If you want the Code to run without User Intervention the Code would need to be revised for those messages that require User Input, such as Select Report Date and Delete and Recreate File. Report Date could be put in as a Default to Today's Date (if that works for you) and Delete and Recreate File could be eliminated and just default to Kill the File.

    Think about what you'd like to happen and when; then I'd suggest you start a New Thread for this issue.

  41. #41
    Registered User
    Join Date
    05-29-2013
    Location
    MIE
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Split and Save as a seprate excel file. How to do it?

    Sure John. I'll think about it and do as you suggested.

    Regards,
    Simplyxl

+ 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