+ Reply to Thread
Results 1 to 2 of 2

MACROS: Sort by multiple criteria - Create tabs based off of criteria

Hybrid View

  1. #1
    Registered User
    Join Date
    07-21-2009
    Location
    Vienna, VA
    MS-Off Ver
    Excel 2007
    Posts
    1

    MACROS: Sort by multiple criteria - Create tabs based off of criteria

    I am trying to create a fairly complex macros for reports that I do at work.

    We are currently using macros and this accomplishes about 70% of what we would like to do. Here is our current macros:

    Sub AddSheets()
        Application.ScreenUpdating = False
        'Sort data on "Formatting - Deltek" worksheet by names in column Q
        Application.Goto Reference:="R7C1:R65536C24"
        ActiveWorkbook.Worksheets("Formatting - Deltek").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Formatting - Deltek").Sort.SortFields.Add Key:= _
            Range("Q7:Q65536"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("Formatting - Deltek").Sort
            .SetRange Range("A7:W65536")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A1").Select
        
        Dim rng As Range
         
        With Sheets("Formatting - Deltek")
            .AutoFilterMode = False
            Sheets.Add().Name = "Temp"
            .Range("Q6", .Range("Q6").End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheets("Temp").Range("A1"), Unique:=True
             
            For Each rng In Sheets("Temp").UsedRange.Offset(1).Resize(Sheets("Temp").UsedRange.Rows.Count - 1)
                .Range("A7").CurrentRegion.AutoFilter field:=17, Criteria1:=rng
                Sheets.Add(After:=Sheets(Sheets.Count)).Name = rng
                .AutoFilter.Range.Copy Sheets(rng.Text).Range("A1")
            Next rng
             
            .AutoFilterMode = False
            Application.DisplayAlerts = False
            Sheets("Temp").Delete
            Application.DisplayAlerts = True
             
        End With
        
        Dim wsheet As Worksheet
        Dim Last_Row As Long
        For Each wsheet In Sheets
            If wsheet.Name <> "Sub Query" And wsheet.Name <> "LDSUBREC (Voucher Query)" And wsheet.Name <> "Formatting - Deltek" Then
                Sheets("Formatting - Deltek").Rows("1:5").Copy
                wsheet.Rows(1).Insert
                wsheet.Columns("A:G").ColumnWidth = 17
                wsheet.Columns("H:K").ColumnWidth = 10
                wsheet.Columns("L:N").ColumnWidth = 7
                wsheet.Columns("O:O").ColumnWidth = 13
                wsheet.Columns("P:P").ColumnWidth = 10
                wsheet.Columns("Q:Q").ColumnWidth = 7
                wsheet.Columns("R:R").ColumnWidth = 20
                wsheet.Columns("S:S").ColumnWidth = 17.14
                wsheet.Columns("T:T").ColumnWidth = 12
                wsheet.Columns("U:W").ColumnWidth = 10
                wsheet.Rows(6).RowHeight = 32.25
                wsheet.Range("Q7").Copy
                wsheet.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone
                Last_Row = wsheet.Range("D65536").End(xlUp).Row
                wsheet.Range("D" & Last_Row + 1).Formula = "=Sum(D7:D" & Last_Row & ")"
                With wsheet.Range("D65536").End(xlUp)
                    With .Borders(xlEdgeTop)
                        .LineStyle = xlContinuous
                        .ColorIndex = 0
                        .TintAndShade = 0
                        .Weight = xlThin
                    End With
         
                    With .Borders(xlEdgeBottom)
                        .LineStyle = xlDouble
                        .ColorIndex = 0
                        .TintAndShade = 0
                        .Weight = xlThick
                    End With
         
                    With .Font
                        .Name = "Calibri"
                        .Size = 12
                        .Strikethrough = False
                        .Superscript = False
                        .Subscript = False
                        .OutlineFont = False
                        .Shadow = False
                        .Underline = xlUnderlineStyleNone
                        .ColorIndex = xlAutomatic
                        .TintAndShade = 0
                        .ThemeFont = xlThemeFontMinor
                    End With
                End With
            End If
        Next wsheet
        Application.ScreenUpdating = True
    End Sub

    This takes a list of information and breaks it out into tabs in Excel based on the names as well as formats them. There is one problem with this. After this break-down happens I need to further break down those tabs based on another column containing invoice numbers. So for example I would have the following tab titles (Apple (Invoice 1), Apple (Invoice 2), Microsoft (Invoice 1), Microsoft (Invoice 2)). Is there anyone that could help me?

    Thanks,
    Sean
    Last edited by svineyard; 07-21-2009 at 11:13 AM. Reason: Moderator request

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Advance Macro Help

    Welcome to the forum.

    Please take a few minutes to read the forum rules, amend your thread title appropriately, and edit your post to add code tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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