+ Reply to Thread
Results 1 to 8 of 8

Macro to sort multiple ranges in a single sheet

  1. #1
    Registered User
    Join Date
    04-07-2011
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    49

    Question Macro to sort multiple ranges in a single sheet

    I need to make a macro that can select a range of cells and sorts by column A. Then select and sort the next range of cells. I was thinking that it could select based on cells in column D stopping to sort when it hits the highlighted blank cell, and then end the macro when it hits a blank unhighlighted cell. But I have no idea how to do that.

    I'm uploading an example, this is how the sheet comes to me after exporting it from another program. As you can see, the size of each range varies, and the number of ranges varies as well. Any direction you could give would be helpful.

    Thanks!

    -Michael
    Attached Files Attached Files
    Last edited by imogul; 04-21-2011 at 01:48 PM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to sort multiple ranges in a single sheet

    Hi Michael

    What is it you wish to end up with...the entire file sorted on Column A without the #N/A's? If so, simply do a filter on column A selecting only the #N/A's, delete them then sort.

    If this is not what you're looking for, please explain further.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    04-07-2011
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Macro to sort multiple ranges in a single sheet

    I need multiple sections to be sorted. In this example it would be Rows 2-14, 15-34, and 35-46. This changes every time I run the report though. The #N/A can be ignored. It's the total row for each section and because of the # it always sorts to the bottom of the section. I just need a macro that will sort multiple different ranges within the sheet.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to sort multiple ranges in a single sheet

    Hi Michael

    See if this code does as you require. Let me know of issues.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    04-07-2011
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Macro to sort multiple ranges in a single sheet

    Hey John thanks for the code. Sorry it took me so long to repost, it's been nuts over here and I just now had time to look at it. It does work great except for one thing. The NA Total rows. Turns out I do need them as is. The #NA is the result of a Vlookup formula. Is there a way to tweak the macro so it doesn't clear those cells?

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to sort multiple ranges in a single sheet

    Hi Michael

    It won't be "tweaking" the code...I don't think. The #N/A cells were central to the proposed code. It'll probably require a rewrite...let me look at it.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to sort multiple ranges in a single sheet

    Hi Michael

    See if this does as you need. Let me know of issues.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-07-2011
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Macro to sort multiple ranges in a single sheet

    That worked like a charm! Thank you so much for taking the time to reply. I really appreciate it.

+ 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