+ Reply to Thread
Results 1 to 10 of 10

Macro to Sort Multiple Dynamic Ranges by Date

  1. #1
    Registered User
    Join Date
    08-13-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    5

    Macro to Sort Multiple Dynamic Ranges by Date

    I have a sheet with several different sections of rows of data on a sheet. Each section contains a variable amount of rows below it but the same amount of columns.

    Column A contains the heading of the section and then in the rows of data below, the date for each row. I need a macro that will sort the rows in each section by this date while keeping the rows in their respective sections, under that section's title. I would want it sorted by oldest at bottom, newest at top. I believe if I set each section as a dynamic range and then run a macro that will sort each named dynamic range I can get the desired outcome but that's as far as I can seem to get.

    The book added has an example of the before (sheet 1) and after (sheet 2) that I am looking for and I have named each range as their respective Section.
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to Sort Multiple Dynamic Ranges by Date

    Hi crikreef,

    Try this

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    08-13-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to Sort Multiple Dynamic Ranges by Date

    That works beautifully. The only problem is that I gave a generic example. I need it to work for sections that have specific names, not the generic Section 1, Section 2 etc...

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to Sort Multiple Dynamic Ranges by Date

    Hi crikreef,

    Perhaps you could just use the one space separator and assume that the first range started in row 2!

    Please Login or Register  to view this content.
    Last edited by xladept; 08-13-2012 at 07:53 PM.

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Macro to Sort Multiple Dynamic Ranges by Date

    Hi crikreef,

    This looks like a Pivot Table answer to me. If you move the section number to a column by itself and then play with the Pivot Table options and design you get what I show in the attached. A single table is much easier to work with than multiple. See if this attached helps.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  6. #6
    Registered User
    Join Date
    08-13-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to Sort Multiple Dynamic Ranges by Date

    Ya I would love to do that, as I'm very comfortable with pivot tables, but the person I'm making it for refuses to use them so I need go this route.

    I did figure out a work around though. I just inserted a new column A, and set the cells next to the dates to pull the date over and then added the generic section headings to each section and then hid the column. Seems to be working!

    Thanks for your help.

    Still interested in seeing if it is possible to do the macro for the dynamic ranges though if anyone knows how to do that (or if it is possible)

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,580

    Re: Macro to Sort Multiple Dynamic Ranges by Date

    This should work.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-13-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to Sort Multiple Dynamic Ranges by Date

    Works on the generic book I uploaded but when I try it on my real book it says:

    Run-time error '1004:
    This operation requires the merged cells to be identically sized, even though there are no merged cells on that sheet.

    And the debugger is highlighting

    .Sort key1:=.Cells(1), order1:=1, Header:=xlYes


    Attached is another workbook that is more representative of what I need the macro to work on.
    Attached Files Attached Files
    Last edited by crikreef; 08-13-2012 at 08:43 PM.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,580

    Re: Macro to Sort Multiple Dynamic Ranges by Date

    Merged cell?
    I don't see any of them
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-13-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to Sort Multiple Dynamic Ranges by Date

    I found it. It wasn't in the book I uploaded. It was in one the cells that I had deleted before uploading the cleaner version. Looks like it works!

    Thanks!

+ 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