+ Reply to Thread
Results 1 to 3 of 3

Macro to split Large Worksheet Into Multiple Tabs

Hybrid View

asmith08 Macro to split Large... 04-01-2014, 06:54 PM
stnkynts Re: Macro to split Large... 04-01-2014, 09:18 PM
asmith08 Re: Macro to split Large... 04-02-2014, 06:45 PM
  1. #1
    Registered User
    Join Date
    05-19-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    2

    Macro to split Large Worksheet Into Multiple Tabs

    Hello to all experts:

    I am trying to figure out an advanced way to split data from one tab into multiple tabs based on a certain criteria. I am attaching a sample workbook to this post for reference.

    1. The criteria to split to different tabs is in Column E. I would also like the new tab to have the name of the Unique ID in Column E.
    2. This list is dynamic so it could have from 5,000 to 30,000 lines.
    3. Also, the criteria in Column E may not remain the same month to month. (i.e. some other ID's could be added or taken away from month to month), so I would need a way to pick up new ID's if one exists next time.

    I can record the macro using filters, but I would like a shorter, less complicated macro, and I am not that far in my excel knowledge.

    Thanks for all your help!

    Data.xlsm

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to split Large Worksheet Into Multiple Tabs

    Give this a try. It took my comp about 1.5 seconds to work through it all.

    Sub Extract_Uniques()
    Dim ws As Worksheet:    Set ws = Sheets("Data Values")
    Dim wksht As Worksheet
    Dim lastrow As Long, lArray As Long
    Dim arrUniques() As String
    Dim bDimarr As Boolean
    Dim rCell As Range
    
    Application.ScreenUpdating = False
    
    'establish unique values
    lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row
    ws.Range("E1:E" & lastrow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=ws.Range("A" & lastrow + 1), Unique:=True
    
    'set up array of unique values
    bDimarr = False
    
    For Each rCell In ws.Range("A" & lastrow + 2, "A" & ws.Range("A" & Rows.Count).End(xlUp).Row)
        If Not IsEmpty(rCell) Then
            If bDimarr = True Then
                ReDim Preserve arrUniques(0 To UBound(arrUniques) + 1) As String
            Else
                ReDim Preserve arrUniques(0 To 0) As String
                bDimarr = True
            End If
            arrUniques(UBound(arrUniques)) = rCell.Value
        End If
    Next rCell
    
    'clear temp range
    ws.Range("A" & lastrow + 1, "A" & ws.Range("A" & Rows.Count).End(xlUp).Row).ClearContents
    
    'utilize array to perform main task
    For lArray = LBound(arrUniques) To UBound(arrUniques)
    
        'check for existing sheet
        Set wksht = Nothing
        On Error Resume Next
        Set wksht = Sheets(arrUniques(lArray))
        If wksht Is Nothing Then
            Sheets.Add(After:=Sheets(Sheets.Count)).Name = arrUniques(lArray)
            Set wksht = Sheets(arrUniques(lArray))
        End If
        On Error GoTo 0
        
        'filter values to sheet
        With ws
            .AutoFilterMode = False
            .Range("E1:E" & .Range("E" & Rows.Count).End(xlUp).Row).AutoFilter Field:=1, Criteria1:=arrUniques(lArray)
            .AutoFilter.Range.Offset(1).EntireRow.Copy Destination:=wksht.Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
            .AutoFilterMode = False
        End With
    
    Next lArray
    
    Erase arrUniques
    Application.ScreenUpdating = True
    
    End Sub

  3. #3
    Registered User
    Join Date
    05-19-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Macro to split Large Worksheet Into Multiple Tabs

    This works perfectly for me with a little tweaking.

    Thanks so much!

+ 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] Macro to split worksheet to multiple worksheets
    By daillest319 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-30-2013, 04:58 AM
  2. [SOLVED] Large amt of data needing to be split onto diff tabs
    By Arliene in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-18-2012, 10:00 AM
  3. split tabs into different worksheet
    By cytseng in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-11-2012, 01:31 PM
  4. Replies: 6
    Last Post: 02-01-2012, 05:29 PM
  5. Macro: Split worksheet into tabs.
    By TWent in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-17-2010, 03:48 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