+ Reply to Thread
Results 1 to 6 of 6

Sort by first three characters

  1. #1
    Forum Contributor
    Join Date
    07-27-2012
    Location
    Somerset, Kentucky
    MS-Off Ver
    Excel 2007
    Posts
    123

    Sort by first three characters

    Is it possible to sort a column in VBA by just the first 3 characters in the cells? See below and attached. I want to sort first by Range("A1") but only the first 3 characters in each cell, then sort normally for Range("E1"). I want the counties to stay grouped regardless of what comes after the first 3 characters, but then the phone numbers to by grouped by county. If I sort by phone numbers first, they aren't grouped by county. Here is what I have

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

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Sort by first three characters

    The textbook method is to create another column that extracts the first three characters and use that for sorting.

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Sort by first three characters

    You could use a helper column with =LEFT(A2,3) and then sort on that

  4. #4
    Forum Contributor
    Join Date
    07-27-2012
    Location
    Somerset, Kentucky
    MS-Off Ver
    Excel 2007
    Posts
    123

    Re: Sort by first three characters

    I was hoping not to have to use a helper column. This code is in the middle of a bunch of other code.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Sort by first three characters

    The file you attached does not have any code.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Sort by first three characters

    You can add another column way out to the right, say AYS, then change the code to the following, and it shouldn't affect anything else on your sheet or your other code.

    Please Login or Register  to view this content.

+ 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] sort characters within a cell
    By tehs0001 in forum Excel General
    Replies: 11
    Last Post: 07-31-2015, 02:24 AM
  2. Custom Sort list of more than 255 characters
    By tk85 in forum Excel General
    Replies: 1
    Last Post: 09-25-2014, 04:50 PM
  3. Sort by number of characters?
    By DrSues02 in forum Excel General
    Replies: 5
    Last Post: 01-16-2011, 04:21 PM
  4. Is there a way to sort items by the number of characters?
    By jdwilliams1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-19-2006, 12:56 PM
  5. Ignoring leading characters in a sort
    By tas666 in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 09-21-2006, 03:45 AM
  6. How do I sort in Excel by the no. of characters in a cell?
    By yasmingeo in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-21-2005, 08:05 AM
  7. [SOLVED] I want to sort, ignoring all characters except numbers
    By wojo in forum Excel General
    Replies: 15
    Last Post: 07-08-2005, 05:05 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