+ Reply to Thread
Results 1 to 8 of 8

VBA to split document into separate workbooks

  1. #1
    Registered User
    Join Date
    03-29-2017
    Location
    Chicago, IL
    MS-Off Ver
    Office 2010
    Posts
    4

    VBA to split document into separate workbooks

    Hello,

    I've often read numerous threads for help on here but this is my first post as I was not able to find a solution to this.

    I would like a macro that based on cell value copy the entire row onto a new workbook.

    I have this macro that I have been using but I would like it to now split into separate workbooks instead of sheets. Also if possible have the unique identifier changed from column A to column F. Thanks in advance!

    Option Explicit
    Sub DivisionalSplit()
    Dim wsAll As Worksheet
    Dim wsCrit As Worksheet
    Dim wsNew As Worksheet
    Dim LastRow As Long
    Dim LastRowCrit As Long
    Dim I As Long

    Set wsAll = Worksheets("Detail")

    LastRow = wsAll.Range("A" & Rows.Count).End(xlUp).Row

    Set wsCrit = Worksheets.Add


    wsAll.Range("A1:A" & LastRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wsCrit.Range("A1"), Unique:=True

    LastRowCrit = wsCrit.Range("A" & Rows.Count).End(xlUp).Row
    For I = 2 To LastRowCrit

    Set wsNew = Worksheets.Add
    wsNew.Name = wsCrit.Range("A2")
    wsAll.Rows("1:" & LastRow).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=wsCrit.Range("A1:A2"), _
    CopyToRange:=wsNew.Range("A1"), Unique:=False
    wsCrit.Rows(2).Delete

    Next I

    Application.DisplayAlerts = False
    wsCrit.Delete
    Application.DisplayAlerts = True

    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: VBA to split document into separate workbooks

    Like this? Remember to use wrap your code snippets in code tags - select your code and click the # menu button.
    Please Login or Register  to view this content.
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  3. #3
    Registered User
    Join Date
    03-29-2017
    Location
    Chicago, IL
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: VBA to split document into separate workbooks

    Hey MatrixMan,

    Thanks for the help. Not quite working. It looks like it runs but it does not do anything.

  4. #4
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: VBA to split document into separate workbooks

    The only way this doesn't do anything is if LastRowCrit = 1 (i.e. there is no data in the detail sheet copied to the new sheet). Shooting blind without a sample file showing data and structure ...

  5. #5
    Registered User
    Join Date
    03-29-2017
    Location
    Chicago, IL
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: VBA to split document into separate workbooks

    I've attached a file. So based off this example I'd like (if possible) four files based off column F (10,20,30,40). Thanks in advance!
    Last edited by epidemik; 04-03-2017 at 11:47 AM.

  6. #6
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: VBA to split document into separate workbooks

    This should do it.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-29-2017
    Location
    Chicago, IL
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: VBA to split document into separate workbooks

    Thanks so much this works great.

  8. #8
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: VBA to split document into separate workbooks

    You're very welcome - thanks for the reps :-)

+ 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. [SOLVED] Split pairs of worksheets to separate workbooks
    By vhache in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-17-2016, 05:03 PM
  2. Open, split worksheet into separate workbook, save splited workbooks
    By solti in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2015, 08:17 AM
  3. Split multi-tab workbook into separate workbooks
    By ahurst105 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2013, 06:51 PM
  4. How to split excel file into separate workbooks based on number of columns?
    By nandana83 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2012, 04:03 AM
  5. [SOLVED] Split table, based on two criteria, into separate workbooks
    By gingert88 in forum Excel General
    Replies: 6
    Last Post: 07-10-2012, 06:08 PM
  6. Split Excel report and save separate Workbooks to respective locations
    By seattle in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2010, 03:30 AM
  7. [SOLVED] Macro to Split Workbook into separate Workbooks
    By jmurray in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-14-2009, 04:44 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