+ Reply to Thread
Results 1 to 2 of 2

Sort Columns

  1. #1
    Forum Contributor
    Join Date
    08-20-2005
    Posts
    173

    Sort Columns

    Hi,

    I have 6 columns and 5000 rows.
    My headings are:
    a,b,c,d,e,f

    I need to write a macro which sorts the cols in order:
    a,c,d,b,e,f

    It does need to be a macro, as opposed to manually doing a custom list.
    I have tried writing a macro which involves custom lists (below)
    but doesnt quite work.

    Thanks


    Sub sortcol()

    Range("A1:G12936").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:= _
    xlGuess, OrderCustom:=6, MatchCase:=False, Orientation:=xlLeftToRight, _
    DataOption1:=xlSortNormal
    End Sub

  2. #2
    Tom Ogilvy
    Guest

    RE: Sort Columns

    Sub sortcol()

    Range("A1:G12936").Sort Key1:=Range("A1"), Order1:=xlAscending, _
    Key2:=Range("C1"), Order2:=xlAscending, _
    Key3:=Range("D1"), Order3:=xlAscending, _
    Header:=xlGuess, _
    MatchCase:=False, _
    Orientation:=xlLeftToRight, _
    DataOption1:=xlSortNormal
    Range("A1:G12936").Sort Key1:=Range("B1"), Order1:=xlAscending, _
    Key2:=Range("E1"), Order2:=xlAscending, _
    Key3:=Range("F1"), Order3:=xlAscending, _
    Header:=xlGuess, _
    MatchCase:=False, _
    Orientation:=xlLeftToRight, _
    DataOption1:=xlSortNormal
    End Sub

    --
    Regards,
    Tom Ogilvy


    "T De Villiers" wrote:

    >
    > Hi,
    >
    > I have 6 columns and 5000 rows.
    > My headings are:
    > a,b,c,d,e,f
    >
    > I need to write a macro which sorts the cols in order:
    > a,c,d,b,e,f
    >
    > It does need to be a macro, as opposed to manually doing a custom
    > list.
    > I have tried writing a macro which involves custom lists (below)
    > but doesnt quite work.
    >
    > Thanks
    >
    >
    > Sub sortcol()
    >
    > Range("A1:G12936").Sort Key1:=Range("A1"), Order1:=xlAscending,
    > Header:= _
    > xlGuess, OrderCustom:=6, MatchCase:=False,
    > Orientation:=xlLeftToRight, _
    > DataOption1:=xlSortNormal
    > End Sub
    >
    >
    > --
    > T De Villiers
    > ------------------------------------------------------------------------
    > T De Villiers's Profile: http://www.excelforum.com/member.php...o&userid=26479
    > View this thread: http://www.excelforum.com/showthread...hreadid=565980
    >
    >


+ 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