+ Reply to Thread
Results 1 to 4 of 4

Sort Macro for a Changing Range

  1. #1
    Registered User
    Join Date
    03-03-2010
    Location
    Orlando, Florida
    MS-Off Ver
    Excel 2007
    Posts
    48

    Sort Macro for a Changing Range

    Hey All,

    I want to create a macro that sorts based on five criteria. The data to be be sorted is a range that always begins on the same row (7) but ends on a different row due to adjustments in employee levels. The columns will always remain the same as well.

    Attached is the file in question.

    I want the macro to sort like this:

    Column E (descending)
    Column I (descending)
    Column G (descending)
    Column C (ascending)
    Column A (ascending)

    Like I stated above, the top row will always be Row 7, but the last row will change. Any help is greatly appreciated.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    05-09-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    315

    Re: Sort Macro for a Changing Range

    Hi

    I've added the following code into a module in the attached workbook.

    Dion

    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    03-03-2010
    Location
    Orlando, Florida
    MS-Off Ver
    Excel 2007
    Posts
    48

    Re: Sort Macro for a Changing Range

    Thanks for the quick response, mojo. That works perfectly. Let's say there was another table three blank rows below this one with a different number of rows. How could the code above be modified to sort both these tables by the same criteria?

  4. #4
    Forum Contributor
    Join Date
    05-09-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    315

    Re: Sort Macro for a Changing Range

    You'd need some way of determining the start row of the 2nd table. Perhaps by searching for a unique cell value.

    You can't simply say it's 3 rows below the end of the first table because if you add a 2nd table, you won't be able to determine the last row of the 1st table using the code above (see the line which begins varLastRow = ).

+ 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