Solved

Add an additional sort (Ascending)

Posted on 2011-09-12
6
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

717 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