+ Reply to Thread
Results 1 to 3 of 3

Sort direction selection

Hybrid View

nolloping Sort direction selection 04-26-2007, 07:18 AM
sweep Hi, maybe not directly,... 04-26-2007, 07:22 AM
nolloping Got it, but in an not very... 05-07-2007, 06:44 AM
  1. #1
    Registered User
    Join Date
    01-29-2007
    Location
    Norway
    Posts
    11

    Sort direction selection

    hi,

    I need to find the current application setting for a sort function. is there a way to toggle the way a Sort function use xlDescending and xlAscending.

    Sub SortPerCent()
        Range("i119").Select
        Sort
    End Sub
    Sub Sort()
        a = xlDescending
        b = xlAscending
        
        if application.sortorder = a then  not application.sortorder = a
    
        
        Rows("119:133").Sort Key1:=Selection, order1:=application.sortorder , Header:=xlNo _
            , OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
    I Know sortorder is not a vba function, but it is the best way to describe it. What i am trying to describe is that i need to find the last sort order and the toggle it to the opposite. Is this possible?

    tks,
    Nolloping

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454
    Hi,

    maybe not directly, but you could compare the top and bottom of the range to determine which is larger, and therefore what the current sort order is?
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    01-29-2007
    Location
    Norway
    Posts
    11
    Got it, but in an not very good way.

    Sub SorterWeapons()
        a = xlDescending
        b = xlAscending
        
        myOldSort = Worksheets("Sheet1").Range("a142").Value
        If myOldSort = a Then mySort = b
        If myOldSort = b Then mySort = a
        
        Rows("143:170").Sort Key1:=Selection, order1:=mySort, Header:=xlNo _
            , OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
    
        Worksheets("Sheet1").Range("a142").Value = mySort
    End Sub
    With this code i have to save a variable value to the sheet in order to toggle to the opposite Ascending/Descending value.

    Does anybody know if there is a way to retrieve the applications last sort order? would like to get this in a way without having to save the sort order varable value to the spreadsheet.
    Last edited by nolloping; 05-08-2007 at 05:09 AM.

+ 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