• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

Add an additional sort (Ascending)

Attached is some code that I use to filter a dataset.  After the filter is applied I would like to sort in ascending order oldest to newest, based on column T.

Is there a way to include this in the current filter statements?  

Please advise and thanks. -R-
With rgFilter
        .AutoFilter
        .AutoFilter Field:=7, Criteria1:="SPCLMDL"
                .AutoFilter Field:=10, Criteria1:=Array( _
        "CRTD", "PCNF LKD  REL", "PCNF REL", "REL"), Operator:=xlFilterValues
        .AutoFilter Field:=20, Criteria1:="<=" & Date, Operator:=xlAnd  'Late including today
        
    End With
End With

Open in new window

0
RWayneH
Asked:
RWayneH
  • 4
  • 2
1 Solution
 
SANTABABYCommented:
Please try to add the following code after line 9 (above) and run.

    rgFilter.Select
    ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Add Key:=Range("T1"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveSheet.Sort
        .SetRange rgFilter
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

Open in new window


0
 
RWayneHAuthor Commented:
So do I place this after the current filter?  Is there a way to intergrate it into the current code? rather then having to place it after the current box of code?  It would be nice if I could keep it all together within the same with box. -R-
0
 
SANTABABYCommented:
Please add the following line within the "With rgFilter" code block

  .Sort Key1:=Range("T1"), Order1:=xlAscending, Header:=xlGuess, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod:=xlPinYin
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
RWayneHAuthor Commented:
There is an issue with this solution.  My column headers are now on the bottom instead of the top...  How do I keep the headers at the top?  -R-
0
 
RWayneHAuthor Commented:
Nevermind, I test the one line code and that worked....  THANKS.  The one that threw my headers to the bottom was the first solution...

thank you both!! -R-
0
 
RWayneHAuthor Commented:
EXCELent!!  Thank you so much.  -R-
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now