+ Reply to Thread
Results 1 to 5 of 5

Sort the range as an area

  1. #1
    Registered User
    Join Date
    01-08-2021
    Location
    China, Jiangsu
    MS-Off Ver
    2016
    Posts
    27

    Sort the range as an area

    Hello,
    As shown in the images below, I want to sort a range alphabetically. I know how to sort them in rows or columns separately, but I don't know if range.sort can sort an "area".
    The only solution I have in mind is to read every cell in range into array, sort array, then put the array to the original range. I am feeling there should be a quick method, or are there better ways than my idea?

    Thank you very much.


    Basically, given this range
    1.png

    I want it to be sorted like this
    2.png

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Sort the range as an area

    I don't know of a "quicker" method than the array method you described.

    The built in Sort feature doesn't sort and area in one step as you requested. You could loop it for each column and row as below, but it wouldn't be any faster or more elegant than sorting an array.

    Please Login or Register  to view this content.
    An array sort would be my preference.
    Last edited by AlphaFrog; 04-15-2021 at 07:30 AM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,577

    Re: Sort the range as an area

    Here is the code for macro
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Sort the range as an area


    Hi !

    Quote Originally Posted by dexiongmao View Post
    The only solution I have in mind is to read every cell in range into array, sort array, then put the array to the original range.
    It's a good idea, the sort can de done just using an Excel basics, just need an attachment to work on …

  5. #5
    Registered User
    Join Date
    01-08-2021
    Location
    China, Jiangsu
    MS-Off Ver
    2016
    Posts
    27

    Re: Sort the range as an area

    Thank you all for your answers!

    Here is my code after considering your suggestions, though I didn't use the actual concept of array. Instead, I put them in one column and used the built in Sort feature. Please let me know if there can be any improvements.

    Please Login or Register  to view this content.
    Last edited by dexiongmao; 04-15-2021 at 10:13 PM.

+ 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. Trying to auto sort and set the print area for a report
    By Prill in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-02-2020, 04:12 PM
  2. VBA code for Sort Ascending to specified area
    By tkoral in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2017, 11:19 PM
  3. Why does the sort area change?
    By paulo57509 in forum Excel General
    Replies: 8
    Last Post: 04-06-2015, 07:49 PM
  4. [SOLVED] Change default to expand sort area or not
    By ajan in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-22-2014, 04:10 PM
  5. Set Print Area based on Sort
    By crjpilot in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-16-2008, 09:36 AM
  6. [SOLVED] How do I sort area codes by time zones
    By Paul in forum Excel General
    Replies: 1
    Last Post: 08-04-2005, 04:05 AM
  7. Defining area codes per state to sort
    By jshgolf in forum Excel General
    Replies: 2
    Last Post: 07-01-2005, 01:13 PM

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