+ Reply to Thread
Results 1 to 3 of 3

Custom Sort based off first three characters

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-12-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    163

    Question Custom Sort based off first three characters

    Is it possible to create a VBA custom sort looking at only the first 3 characters in the cells. I'm trying to sort a huge list of item numbers into catagories. the first three characters can identify what catagory it belongs to.
    for example there are two catagories Roadway and Pavement
    these are the item numbers
    202E23500 would go with Roadway
    254E01000 would go with Pavement
    407E10000 would go with Pavement
    202E01000 would go with Roadway
    209E72001 would go with Roadway

    (this is drastically simplified)

    so you see the first three characters (202 and 209 for Roadway 254 and 407 for Pavement) is what I want to sort off of
    I can make a list to base the custom sort off of which three characters go with each catagory. There are just way to many item numbers to create a custom sort base off the whole number.

    I would like that example list to Sort like this

    Roadway
    202E01000
    202E23500
    209E72001
    Pavement
    254E01000
    407E10000

    I can add the Catagory names in the column with the Item numbers to make it easier to sort.

    any help with this code would be awesome I can edit the code to make it apply to the whole set of data but i just dont know if this is possible or how to do it.

    JD

  2. #2
    Forum Contributor
    Join Date
    08-12-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Custom Sort based off first three characters

    i uploaded an example file to show a sample of the original data and what i want after running the macro
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: Custom Sort based off first three characters

    Hi Jed
    You dont need a macro/VBA to do this. You can create a separate column containing the first 3 characters of your Roadway and use this column for your sort. Use this formula in the first cell of the column (adjust if you need to).

    For example if your Roadway is column A, inset a new column before Column A and put this formula into Cell A1 and copy down.

    =MID(B1,1,3)

    This will copy the first three characters only of the Roadway to the new column. You can then use this column for your sort.
    Hope this helps.
    Good luck.
    Tony

+ 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