+ Reply to Thread
Results 1 to 3 of 3

Split Master Sheet into Separate Tabs based on data & rename tab

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Sefton
    MS-Off Ver
    MS Office 365 ProPlus
    Posts
    133

    Split Master Sheet into Separate Tabs based on data & rename tab

    I've been searching around trying to see if I can find someone who's already asked a similar question, no doubt there has been but since I'm still a little unsure about loops (which is what I think I need) I've not been able to translate anything into working for me.

    Essentially; I have a worksheet with 11 columns, and varying numbers of rows, of data each week. One of the columns is the email address of the user. I want to be able to split the data into separate tabs based on the email address - and then rename the tab to the email address (column D).
    So each new tab will have 5/6+ rows of data copied from the master, and the tab will be named by the users email address

    Since the number of rows/users can vary, I need something that keeps checking until it reaches the end of the data rather than a pre-set end point, which is where I'm struggling (though I'm also struggling with having the renaming happen as part of the macro also).

    Thanks in advance for any help.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,031

    Re: Split Master Sheet into Separate Tabs based on data & rename tab

    This assumes that your table on the activesheet starts in cell A1:

    Sub SplitDataBase()
        Dim C As Range
        Dim DSh As Worksheet
        Dim ASh As Worksheet
        Dim strName As String
        Dim rngC As Range
        Dim lngKC As Long
        
        'Optional code to select key column
        'Set rngC = Application.InputBox("Select a cell in the key column", Type:=8)
        'lngKC = rngC.Column
        
        'Code to specify key column (4 \is column D)
        lngKC = 4 'Key Column 1 = A, 2 = B etc.
        
        Application.DisplayAlerts = False
        Application.EnableEvents = False
    
        Set ASh = ActiveSheet
        Set rngC = ASh.Range("A1").CurrentRegion
        With ASh
            rngC.Columns(lngKC).AdvancedFilter Action:=xlFilterCopy, _
                CopyToRange:=.Cells(.Rows.Count, lngKC).End(xlUp)(3), Unique:=True
            With .Cells(.Rows.Count, lngKC).End(xlUp).CurrentRegion
                For Each C In .Cells.Offset(1).Resize(.Cells.Count - 1, 1)
                    If C.Value <> "" Then
                        On Error Resume Next
                        Worksheets(C.Value).Delete
                        On Error GoTo 0
                        Set DSh = Worksheets.Add(after:=Worksheets(Worksheets.Count))
                        DSh.Name = C.Value
                        rngC.AutoFilter Field:=lngKC, Criteria1:=C.Value & "*"
                        rngC.SpecialCells(xlCellTypeVisible).Copy DSh.Range("A1")
                        rngC.AutoFilter
                        DSh.Cells.EntireColumn.AutoFit
                    End If
                Next C
                .Clear
            End With
        End With
        
        If MsgBox("Export the new sheets to files?", vbYesNo) = vbYes Then
            For Each DSh In ActiveWorkbook.Worksheets
                If DSh.Name <> ASh.Name Then
                    DSh.Move
                    ActiveWorkbook.SaveAs ThisWorkbook.Path & "\Workbook " & ActiveSheet.Name & ".xlsx"
                    ActiveWorkbook.Close
                End If
            Next DSh
        End If
    
        Application.DisplayAlerts = True
        Application.EnableEvents = True
        
    End Sub
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Sefton
    MS-Off Ver
    MS Office 365 ProPlus
    Posts
    133

    Re: Split Master Sheet into Separate Tabs based on data & rename tab

    Perfect!

    This does exactly what I need, thanks.

+ 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] Convert Master Data to Templates in Separate Tabs based on Unique IDs
    By paula.mccall in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-03-2023, 02:55 PM
  2. [SOLVED] Split master sheet into multiple sheet and rename those with variable first two letter.
    By sarat47 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2020, 10:56 AM
  3. Summarize data from a master data sheet into separate tabs
    By AndreaJean18 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-23-2019, 02:14 PM
  4. Master Sheet to divide into 2 separate tabs with formatting
    By SBennett212 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-03-2019, 06:55 AM
  5. Replies: 19
    Last Post: 02-05-2018, 06:45 PM
  6. Replies: 1
    Last Post: 09-15-2014, 01:03 PM
  7. Break apart master into separate tabs based on name
    By WNErika in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-25-2012, 02:13 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