Results 1 to 10 of 10

Thread: Sum if

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    I was able to use a sort code to sort by custodian first and then the above code worked. Thanks for the help!
    FYI - this came from another thread i started to sort data..thanks Paul Hossler for the code help!

    Option ExplicitSub SortByColG()
        Dim rBroker As Range, rArea As Range, rSort As Range
        
        
        Set rBroker = ActiveSheet.Columns(1).SpecialCells(xlCellTypeConstants, 23)
        
        For Each rArea In rBroker.Areas
            Set rSort = rArea.CurrentRegion
            
            'adjust for header row and custodian row
            If rSort.Rows(1).Row = 1 Then
                'header row + total row + single data row = 3 rows so no need to sort
                If rSort.Rows.Count <= 3 Then GoTo NextArea
                Set rSort = rSort.Cells(3, 1).Resize(rSort.Rows.Count - 2, rSort.Columns.Count)
            Else
                'NO header row + total row + single data row = 2 rows so no need to sort
                If rSort.Rows.Count <= 2 Then GoTo NextArea
                Set rSort = rSort.Cells(2, 1).Resize(rSort.Rows.Count - 1, rSort.Columns.Count)
            
            End If
            
            With ActiveSheet.Sort
                .SortFields.Clear
                .SortFields.Add Key:=rSort.Columns(7), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
                .SetRange rSort
                .Header = xlNo
                .MatchCase = False
                .Orientation = xlTopToBottom
                .SortMethod = xlPinYin
                .Apply
            End With
    NextArea:
        Next
        
        Range("A1").Select
         End Sub
    Last edited by Klartigue; 01-08-2015 at 12:35 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •