+ Reply to Thread
Results 1 to 5 of 5

Save a sorting rule

  1. #1
    Registered User
    Join Date
    02-07-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    42

    Save a sorting rule

    Hi,
    I need to sort a set of cells repeatedly using a sorting rule that has multiple levels (e.g., sort on date from largest to smallest, then sort on sales total from largest to smallest, then sort on years with the company from largest to smallest etc.) It takes a while to set up the sorting rule each time.
    I currently use Data ribbon, then Sort icon on that ribbon.

    Is there a way to save a sorting rule like that and then reuse it?

    Many thanks!
    Studiosa.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: is there a way to save a sorting "rule"?

    Only with VBA I think. Try recording a macro and if you want a hand tidying the code up to work with variable ranges post back.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    02-07-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: is there a way to save a sorting "rule"?

    Dom,
    Thank you very much. I am not up to VBA, I am afraid. Still learning the basics.

    Studiosa

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: is there a way to save a sorting "rule"?

    Recording a macro will replicate your action in code. The range references will be hard coded but this can be relatively easily corrected.

    Dom

  5. #5
    Registered User
    Join Date
    02-07-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Save a sorting rule

    Dear Dom,
    Thank you very much for your previous answer. It took me a while to get the time and the courage to forge into macros/VBA. I finally launched myself into this area of Excel.

    As per your suggestion, I recorded the macro. Actually, I recorded two versions of the macro. The first version("sort_macro_w_clear_filter") starts by eliminating all filtering from the table of data, then sorts the table. The second version ("sort_macro_no_clear_filter") does not have the step of clearing the filter, but just goes straight to sorting. If the table happens to be filtered before I run the macro, "sort_macro_no_clear_filter" does not do the right job (because it "does not see" the hidden rows of the table).

    The main difference between these 2 macros is that the "correct" macro has this line:
    ActiveSheet.ShowAllData
    But the incorrect macro does not have this line.

    The problem is that the "correct" version of the macro ("sort_macro_w_clear_filter") sometimes produces and error. Of course, now that I am writing the message, I cannot reproduce the error. But it seemed to happen some of the time (not all of the time) when I filtered the table before running the macro.
    I am not sure whether this gives you enough information to tell me why I have this "occasional failure". Are these specific known conditions that cause ActiveSheet.ShowAllData
    to fail?

    I attached an example of what I was working on.

    Studiosa.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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