Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Jun 2003
    Location
    Utah, USA
    Posts
    412
    Thanks
    39
    Thanked 5 Times in 5 Posts

    Reversible Sorting (2003 Sp1)

    I forgot to add this idea to the last post.

    I routinely sort a spreadsheet by (say) column A, then column B, then back to column A later. How can I automate this with VBA?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reversible Sorting (2003 Sp1)

    Try recording your actions in a macro.

  3. #3
    4 Star Lounger
    Join Date
    Jun 2003
    Location
    Utah, USA
    Posts
    412
    Thanks
    39
    Thanked 5 Times in 5 Posts

    Re: Reversible Sorting (2003 Sp1)

    I should've mentioned that I had already done that.

    I'd feel more comfortable with VBA if it is possible/feasible.

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reversible Sorting (2003 Sp1)

    If you recorded it, you got VBA code. That is what recording produces.
    Legare Coleman

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Reversible Sorting (2003 Sp1)

    For something this simple the only inefficiency the recorder will produce is some duplication. For instance you can collapse:

    Columns("F:F").Select
    Selection.Sort Key1:=Range("F1"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal

    into

    Columns("F:F").Sort Key1:=Range("F1"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal

    If you are getting into macros and coding, search this Forum and the VBA forum for discussion on recommendations on Excel VBA "how to" textbooks, and keep asking questions here.
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    4 Star Lounger
    Join Date
    Jun 2003
    Location
    Utah, USA
    Posts
    412
    Thanks
    39
    Thanked 5 Times in 5 Posts

    Re: Reversible Sorting (2003 Sp1)

    Thanks folks. I just needed some hand holding.

    The recorded macro works fine.

    FYI: I code a lot, but mostly in Java and the linear algebra sub-languages (Gauss and Matlab). I tend to play dumb when doing Office VBA because you folks have solutions that are so much more elegant than what I come up with on my own.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •