+ Reply to Thread
Results 1 to 3 of 3

Tidying up code: Sorting using autofilter and multiple keys

  1. #1
    Registered User
    Join Date
    06-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Arrow Tidying up code: Sorting using autofilter and multiple keys

    I'm trying to tidy up some code I recorded which sorts filtered data by three different columns.

    1) Can I put multiple sort keys together so I don't have to repeat the 'Active Workbook. Worksheets....' text? I have seen numbers used elsewhere (eg Key1:=... Order1:=...), but I cannot seem to make it work in my code.

    2) Are there any other bits of code I could remove and it still do the same thing?

    This is my current code: (ClearData refers to a variable which picks up the last row of data on the worksheet.)

    Please Login or Register  to view this content.

    Any help would be much appreciated; this bit of code gets repeated quite a few times with differing sort criteria, hence my desire to shorten it!

    Thanks

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Tidying up code: Sorting using autofilter and multiple keys

    you can do all these within scope of with - end with so:

    Please Login or Register  to view this content.

    Key1, Order1 etc can be for sure used in Range.Sort (older version, typical for excel 2003 end older, limited to only 3 keys)
    I am not sure if it also appliest to Autofilter.Sort (?)
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    06-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Tidying up code: Sorting using autofilter and multiple keys

    Thanks Kaper. It doesn't shorten it much, but it does cut out a bit of text :-)

    And thanks for explaining about Key1, Order1 etc - I probably was looking at an older excel macro.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 9
    Last Post: 11-19-2013, 06:17 AM
  2. Tidying up VBA code
    By MrBibby in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2013, 07:29 PM
  3. tidying up code
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2011, 10:03 AM
  4. code tidying
    By stevesunfold in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-26-2008, 05:23 PM
  5. [SOLVED] Help with tidying up code please
    By Andy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-10-2005, 01:00 AM

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