+ Reply to Thread
Results 1 to 5 of 5

Sort Data in ascending order from an Alphanumeric column

  1. #1
    Registered User
    Join Date
    08-29-2019
    Location
    Palo Alto, CA
    MS-Off Ver
    2010
    Posts
    2

    Sort Data in ascending order from an Alphanumeric column

    Hello everyone-
    this is my first post on this website, so I apologize for the mistakes I am sure I will make.

    Essentially I have what I thought was a very simple problem that I have spent over a week on now. I have a large data set that I need to sort by ascending alphanumeric order. My data would look something like this:
    1E
    2F
    1C
    4D
    etc. I need it to look like this:
    1A
    1B
    1C
    2A
    2B
    2C
    etc.
    What I am looking for is an excel macro to do this in VBA. I have automated quite a bit of other things to get the data to this point and would like to add to it so the VBA will then sort all of it by this order. Currently my workaround has been this:
    I make two new columns, one with this formula:
    =IF(LEN(A4)=2,"0"&LEFT(A4,1),LEFT(A4,2))
    It grabs the digit, converts it to a number and if it is single digit puts a 0 in front.
    I then in the other column put
    =Right(A4,1) which grabs the letter (it is always the right most character)
    I can then sort the sheet by selecting sort, then sort and selecting column B then C to sort all the data in a multi level approach.

    What I would like is a simple vba macro to automate this so I can just sort the sheet by the alphanumeric data in the one column. I have tried so many different resources and have not found a simple workaround for this. Any help would be wonderful. Thank you!
    Attached Files Attached Files
    Last edited by jheiler1; 08-29-2019 at 04:08 PM. Reason: Add sample Data

  2. #2
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,001

    Re: Sort Data in ascending order from an Alphanumeric column

    Try this:
    The code is using col BA as a temporary column (it doesn't need the two new columns with formula.)

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Sort Data in ascending order from an Alphanumeric column

    Hello and welcome to the forum,

    Here's a suggestion for you :

    The macro store the data in a array (for faster processing), then add a temporary column to that array to create the list of values in the ##x format (adding 0 if required)
    Then we sorted on the last column and output the result.
    In the example, the data is output to a second sheet that must exist first.

    (The Sort2DVert sub has been in my toolkit for years now... I don't remember where I found it but it's quite handy to sort arrays)

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

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

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

    Re: Sort Data in ascending order from an Alphanumeric column

    Re: your PM.

    Try
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-22-2021
    Location
    Colombus,Ohio
    MS-Off Ver
    16.54
    Posts
    1

    Re: Sort Data in ascending order from an Alphanumeric column

    Hi, I am very new to VBA and am trying to use this function. Will this just sort the 'A' column alphanumerically in ascending order? If so, and I wanted to sort my 'B' column, would I just replace the A's with B's?

+ 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. [SOLVED] Help! Sort Data in Ascending Order which contains duplicates!
    By ironfelix717 in forum Excel General
    Replies: 7
    Last Post: 11-19-2017, 03:32 AM
  2. Replies: 1
    Last Post: 01-16-2016, 02:07 AM
  3. Replies: 2
    Last Post: 01-16-2016, 01:41 AM
  4. [SOLVED] How to sort a column from ascending order that has doubles in it???
    By greenfox74 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-25-2015, 10:54 PM
  5. Arranging worksheets in alphanumeric ascending order
    By ahsanzafar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-19-2015, 05:17 PM
  6. [SOLVED] Find column location by header and then sort rows below it be ascending order
    By Boo123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-04-2015, 11:58 AM
  7. [SOLVED] Data validation special case (alphanumeric ascending order)
    By torers in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-30-2015, 06:25 AM

Tags for this Thread

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