+ Reply to Thread
Results 1 to 4 of 4

Split data into separate worksheets and sort

Hybrid View

  1. #1
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Split data into separate worksheets and sort

    Quote Originally Posted by jxm1092 View Post
    and the data on each individual worksheet can be put in order by time that would be great. Also were would be a great place to get some insight on how to write these types of macros myself?

    Thanks eveyrone.
    Sub test()
        Dim x, e
        Application.ScreenUpdating = False
        With Sheets("R1_1375_test").Cells(1).CurrentRegion
            .Sort key1:=.Cells(1, 3), order1:=1, key2:=.Cells(1, 2), order2:=1, Header:=xlYes
            With .Offset(1).Resize(.Rows.Count - 1).Columns("c")
                x = Filter(.Parent.Evaluate("transpose(if(countif(offset(" & _
                .Address & ",0,0,row(1:" & .Rows.Count & "))," & .Address & _
                ")=1," & .Address & ",char(2)))"), Chr(2), False)
            End With
            For Each e In x
                If Not IsSheetExists(e) Then Sheets.Add(after:=Sheets(Sheets.Count)).Name = e
                Sheets(e).Cells.Clear
                .AutoFilter 3, e
                .Copy Sheets(e).Cells(1)
                With Sheets(e).Cells(1).CurrentRegion
                    .Sort .Cells(1, 2), 1, Header:=xlYes
                    .Columns.AutoFit
                End With
                .AutoFilter
            Next
            .Sort .Cells(1), 1, Header:=xlYes
            .Parent.Activate
        End With
        Application.ScreenUpdating = True
    End Sub
    
    Function IsSheetExists(ByVal txt As String) As Boolean
        On Error Resume Next
        IsSheetExists = Len(Sheets(txt).Name)
        On Error GoTo 0
    End Function
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Split data into separate worksheets and sort

    Sub sheets_from_col3()
    
    Const cl& = 3
    Const sh1 As String = "R1_1375_test"
    Dim a As Variant, x As Worksheet, sh As Worksheet
    Dim rws&, cls&, p&, i&, rr&, b As Boolean
    Application.ScreenUpdating = False
    Sheets(sh1).Activate
    rws = Cells.Find("*", , , , xlByRows, xlPrevious).Row
    cls = Cells.Find("*", , , , xlByColumns, xlPrevious).Column
    Set x = Sheets.Add(After:=Sheets(sh1))
    Sheets(sh1).Cells(1).Resize(rws, cls).Copy x.Cells(1)
    Set a = x.Cells(1).Resize(rws, cls)
    a.Sort a(1, cl), 2, Header:=xlYes
    a = a.Resize(rws + 1)
        p = 2
        For i = p To rws + 1
            If a(i, cl) <> a(p, cl) Then
                b = False
                For Each sh In Worksheets
                    If sh.Name = a(p, cl) Then b = True: Exit For
                Next
                If Not b Then
                    With Sheets.Add
                        .Name = a(p, cl)
                        x.Cells(1).Resize(, cls).Copy .Cells(1)
                        rr = .Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
                        x.Cells(p, 1).Resize(i - p, cls).Cut .Cells(rr, 1)
                        .Columns.AutoFit
                    End With
                End If
                p = i
            End If
        Next i
    Application.DisplayAlerts = False
        x.Delete
    Application.DisplayAlerts = True
    Sheets(sh1).Activate
    Application.ScreenUpdating = True
    
    End Sub

+ 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 worksheets to separate files
    By ksteffin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-10-2013, 06:04 AM
  2. Replies: 1
    Last Post: 03-29-2013, 03:06 PM
  3. Split data by Criteria into separate worksheets on one workbook
    By TrebleC in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-05-2013, 08:39 AM
  4. Split into Separate Worksheets
    By bigroo1958 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-15-2010, 10:54 AM
  5. Split my data into separate worksheets
    By drunk8gods in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-12-2010, 04:20 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