+ Reply to Thread
Results 1 to 10 of 10

Modify Excel Code to split multiple worksheets based on criteria

  1. #1
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Modify Excel Code to split multiple worksheets based on criteria

    Hi All

    I have this code which splits the multiple excel worksheets into individual excel file and saves it all in location as specified.
    Each Excel file is named after the sheet name.
    I basically have 5 sheets say MODELA, MODELB, MODELC, MODELD,and MODELE.
    what i want is, I have one more Sheet called DATA, which needs to come along with each 5 Workbook after the split.
    Ex: ModelA work book shoul have MODELA sheet and DATA Sheet but the excel file name should be MODELA and So on.

    Please Login or Register  to view this content.
    Thanks in advance

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Modify Excel Code to split multiple worksheets based on criteria

    You can copy each worksheet along with the sheet 'DATA' like this.
    Please Login or Register  to view this content.
    That would replace ws.Copy in your code, and you would need to alter the code to skip the 'DATA' sheet in the loop.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Modify Excel Code to split multiple worksheets based on criteria

    Hi Norie

    Thanks for that.
    When i run the above code it returns an error.
    It says Method 'Copy' of object 'sheets' failed at this line.
    Please Login or Register  to view this content.
    What could be the problem?

    Thanks again

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Modify Excel Code to split multiple worksheets based on criteria

    Is the sheet 'DATA' in the same workbook as the code and the sheets you want to split out to new workbooks?

    Is it's exact name 'DATA'?

  5. #5
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Modify Excel Code to split multiple worksheets based on criteria

    Only one workbook gets generated that is ModelA with data sheet.
    Before the second it returns the above error.

  6. #6
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Modify Excel Code to split multiple worksheets based on criteria

    Yes its in same workbook and the name is exact DATA.
    The first MODELA gets generated along with DATA sheet and then it stops.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Modify Excel Code to split multiple worksheets based on criteria

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  8. #8
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Modify Excel Code to split multiple worksheets based on criteria

    Hi Norie Im trying to upload the file, but somehow it wouldnt work.
    May be uploading facility is disabled at the place where im working.

  9. #9
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Modify Excel Code to split multiple worksheets based on criteria

    Hi Norie
    I dono much about VBA but your code below, are we ending both If statements?
    Please Login or Register  to view this content.
    Thanks

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Modify Excel Code to split multiple worksheets based on criteria

    The Ifs in the original code are single line Ifs so don't need an End If.

    The If I added is a block If and requires an End If, and there's one there.

    If there was a problem with the Ifs or any other syntax the code wouldn't even run, you would get a compile error.

+ 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. Replies: 4
    Last Post: 04-05-2016, 12:19 AM
  2. [SOLVED] Split Excel sheets to multiple Workbooks based on Criteria in Cell A1
    By mflank in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-10-2016, 09:58 AM
  3. [SOLVED] HELP!!- modify code so only data based on criteria is copied over
    By indik in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-15-2015, 08:14 AM
  4. [SOLVED] Need to modify VBA code to move Entries between Worksheets based on Drop-down Entry
    By loydancer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-02-2015, 01:56 AM
  5. [SOLVED] Split data into multiple worksheets based empty row
    By calvinle in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-02-2014, 04:59 AM
  6. Modify Code to Run across multiple worksheets in directory
    By tdm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2012, 03:29 PM
  7. Modify code to perform on multiple worksheets
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-07-2011, 11:30 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