Solved

Add an additional sort (Ascending)

Posted on 2011-09-12
6
285 Views
Last Modified: 2012-05-12
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
Comment
Question by:RWayneH
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:SANTABABY
ID: 36525949
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
 

Author Comment

by:RWayneH
ID: 36526864
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
 
LVL 10

Accepted Solution

by:
SANTABABY earned 500 total points
ID: 36531160
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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

Author Comment

by:RWayneH
ID: 36531282
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
 

Author Comment

by:RWayneH
ID: 36531343
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
 

Author Closing Comment

by:RWayneH
ID: 36531353
EXCELent!!  Thank you so much.  -R-
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
EXCEL 2013 question. 4 28
Left trim cells in column A Excel vba 2 32
Unhide very hidden sheets with password 22 45
macro modification Column C 14 31
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question