+ Reply to Thread
Results 1 to 2 of 2

Using VBA To Sort Multiple Criteria

  1. #1
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    Using VBA To Sort Multiple Criteria

    I know I have seen a similar question, but I did a search for "Sorting Multiple Criteria" and did not find what I am looking for.

    Is there a way to use VBA to sort by more than three criteria?

    Specifically four criteria...

    Example: The Header row is row 2

    Selection.Sort _
    Key1:=Range("E2"), Order1:=xlAscending, _
    Key2:=Range("H2"), Order2:=xlAscending, _
    Key3:=Range("B2"), Order3:=xlAscending, _
    Header:=xlNo, OrderCustom:=1, _
    MatchCase:=False, Orientation:=xlTopToBottom

    What the operators would like is

    Selection.Sort _
    Key1:=Range("A2"), Order1:=xlAscending, _
    Key2:=Range("E2"), Order2:=xlAscending, _
    Key3:=Range("H2"), Order3:=xlAscending, _
    Key4:=Range("B2"), Order3:=xlAscending, _
    Header:=xlNo, OrderCustom:=1, _
    MatchCase:=False, Orientation:=xlTopToBottom

    but this creates errors
    Thanks!
    Dennis

    I am using Windows 7 and Office 2007, all of my posts are based on this.

  2. #2
    Chip Pearson
    Guest

    Re: Using VBA To Sort Multiple Criteria

    You need to do two sorts. First sort on the least significant
    columns (typically the right-most columns) then sort on the most
    significant columns (typically the left-most columns).


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com


    "DCSwearingen"
    <[email protected]> wrote
    in message
    news:[email protected]...
    >
    > I know I have seen a similar question, but I did a search for
    > "Sorting
    > Multiple Criteria" and did not find what I am looking for.
    >
    > Is there a way to use VBA to sort by more than three criteria?
    >
    > Specifically four criteria...
    >
    > Example: The Header row is row 2
    >
    > Selection.Sort _
    > Key1:=Range("E2"), Order1:=xlAscending, _
    > Key2:=Range("H2"), Order2:=xlAscending, _
    > Key3:=Range("B2"), Order3:=xlAscending, _
    > Header:=xlNo, OrderCustom:=1, _
    > MatchCase:=False, Orientation:=xlTopToBottom
    >
    > What the operators would like is
    >
    > Selection.Sort _
    > Key1:=Range("A2"), Order1:=xlAscending, _
    > Key2:=Range("E2"), Order2:=xlAscending, _
    > Key3:=Range("H2"), Order3:=xlAscending, _
    > Key4:=Range("B2"), Order3:=xlAscending, _
    > Header:=xlNo, OrderCustom:=1, _
    > MatchCase:=False, Orientation:=xlTopToBottom
    >
    > but this creates errors
    >
    >
    > --
    > DCSwearingen
    >
    > Getting old, but love computers.
    > ------------------------------------------------------------------------
    > DCSwearingen's Profile:
    > http://www.excelforum.com/member.php...o&userid=21506
    > View this thread:
    > http://www.excelforum.com/showthread...hreadid=551157
    >




+ 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