+ Reply to Thread
Results 1 to 4 of 4

Split worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    12-17-2008
    Location
    edinburgh, uk
    Posts
    46

    Split worksheets

    Hi Guys,
    Need a bit of help please:
    In column A of a spread sheet I have lots of entries in this format:

    admin_staff_a_002
    admin_staff_a_006
    admin_staff_1_010
    admin_staff_1_003
    admin_staff_b_005
    admin_staff_z_007
    admin_staff_z_001


    What I need to achieve is to have a different worksheet containing all the rows for admin_staff_a then another for admin_staff_1 etc.

    I want to name each of the worksheets a, 1 etc so i'd remove the admin_staff bit and the _003 bit

    Not sure if I'm being clear enough but its hard to describe!

    Thanks
    Last edited by mattmac; 07-02-2009 at 05:29 AM.

  2. #2
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    Re: Split worksheets

    Hi
    List the names in col A and click the button to run the macro. It creates sheets with names from row 2 to last row
    ravi
    Attached Files Attached Files

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Split worksheets

    This makes a number of assumptions: (1) your data are in A1 down but you have a header in A1 (can be anything) (2) your entries are all the same format "admin_staff_" followed by 1 character followed by "_" followed by three characters (3) column B in your original sheet is clear.
    Sub Macro2()
     
    Dim rng As Range, rng2 As Range, ws As Worksheet
     
    Application.DisplayAlerts = False
    
    With Sheet1
        Sheets.Add().Name = "Temp"
        With .Range("A1", .Range("A1").End(xlDown)).Offset(, 1)
            .Formula = "=LEFT(A1,13)"
            .Value = .Value
            .AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheets("Temp").Range("A1"), Unique:=True
        End With
        Set rng = Sheets("Temp").Range("A2", Sheets("Temp").Range("A2").End(xlDown))
        For Each rng2 In rng
            .Range("A1").AutoFilter field:=2, Criteria1:=rng2
            Set ws = Worksheets.Add(After:=Worksheets(Worksheets.Count))
            .AutoFilter.Range.Copy ws.Range("A1")
            ws.Name = Mid(rng2, 13, Len(rng2) - 12)
        Next rng2
        .Columns(2).Delete
        Sheets("Temp").Delete
        .AutoFilterMode = False
    End With
     
    Application.DisplayAlerts = True
        
    End Sub

  4. #4
    Registered User
    Join Date
    12-17-2008
    Location
    edinburgh, uk
    Posts
    46

    Re: Split worksheets

    Excellent, thank you very much guys!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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