+ Reply to Thread
Results 1 to 5 of 5

Sort a range with numbers, numbers suffix with letter and numbers mixed with text

  1. #1
    Registered User
    Join Date
    10-14-2020
    Location
    USA
    MS-Off Ver
    2010
    Posts
    3

    Sort a range with numbers, numbers suffix with letter and numbers mixed with text

    Hi,

    I have a range with a column containing numbers, numbers suffix with letter and numbers mixed with text. I need a VBA macro that sorts the numbers at the top and numbers with suffixes and numbers with text at the bottom. The column by which they wish to sort is dynamic and the range starts at row 4 and the last used column and row are determined dynamically. Usually the number of columns are around 60, that could change though.

    And the user can sort by column containing numbers, numbers suffix with letter, numbers + text, column containing dates, column containing text, column containing alphanumeric data. Need two separate macros to sort ascending and sort descending.

    I referred to Jindon's code from these threads -> "sorting mixed text and numbers" thread, and "optimize vba code without copy and paste" thread. I'm new to this forum and it won't let me add links.

    But I need help with modifying to suit my needs.

    For example, I would like the sort to return by a column

    11112
    11112C
    12345
    12345A
    12345B
    13456
    13456B
    13456D

    currently it returns
    11112
    12345
    13456
    11112C
    12345A
    12345B
    13456B
    13456D

    Thanks in advance for your help!
    Last edited by lakki; 10-14-2020 at 06:47 PM.

  2. #2
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Sort a range with numbers, numbers suffix with letter and numbers mixed with text

    The problem appears to be that some items, e.g., 11112, are numbers rather than text. If you want ALL ITEMS in this sample column treated the same, they ALL need to be text.

    Simplest way to do that would be to select the entire column (only 1 column at a time), from the ribbon Data tab, Data Tools section, Text to Columns. That should display a wizard dialog. Click the Next button twice to get to Step 3 of 3. In the section in the upper left, select Text. Then click the Finish button. That should have converted all selected cells' contents to text. It should now sort as in your upper list.

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

    Re: Sort a range with numbers, numbers suffix with letter and numbers mixed with text

    Assuming data from A1 down, output the result from B1 down for demonstration purpose.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-14-2020
    Location
    USA
    MS-Off Ver
    2010
    Posts
    3

    Re: Sort a range with numbers, numbers suffix with letter and numbers mixed with text

    This worked. Thanks for your help!

  5. #5
    Registered User
    Join Date
    10-14-2020
    Location
    USA
    MS-Off Ver
    2010
    Posts
    3

    Re: Sort a range with numbers, numbers suffix with letter and numbers mixed with text

    I changed the format as suggested by hrlngrv and it worked.

    I haven't tried this, but have saved in case I run into any issues. I will play around and let you know if any issues.
    Thanks so much for your prompt response!

+ 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. Data Validation with mixed numbers and a single letter
    By TOMS2825 in forum Excel General
    Replies: 5
    Last Post: 08-09-2020, 10:49 AM
  2. [SOLVED] Sort numbers and numbers stored as text separately?
    By Mirisage in forum Excel General
    Replies: 2
    Last Post: 02-05-2019, 11:28 AM
  3. Replies: 11
    Last Post: 04-10-2017, 06:23 AM
  4. Sort Mixed Data With Periods, Letters, Numbers, Backslashes and Hyphens
    By officemate in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 06-16-2015, 01:59 PM
  5. [SOLVED] Convert numbers stored as text to numbers for range of data that changes
    By excel2425 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-06-2014, 01:57 PM
  6. [SOLVED] How to merge a numbers from 3 cells, eliminate repetitive numbers, and sort such numbers?
    By david gonzalez in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-22-2012, 11:59 AM
  7. Sort mixed numbers/letters
    By V-ger in forum Excel General
    Replies: 1
    Last Post: 11-14-2005, 06:55 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