+ Reply to Thread
Results 1 to 10 of 10

Custom Format with Numbers and Letters?

  1. #1
    Registered User
    Join Date
    03-07-2019
    Location
    dsntmttr
    MS-Off Ver
    2016pp
    Posts
    3

    Custom Format with Numbers and Letters?

    I have a column with values like these

    A1
    A-3 // reads: A (minus 3)
    J24
    J-2
    A24
    ...

    Now I want to sort them first by the leading letter. Then by the following number. But Excel reads the minus as dash and sorts it like that
    Please Login or Register  to view this content.
    There are special occasions where we got a trailing zero, too
    Please Login or Register  to view this content.
    What I want my A-Z sorting to look like

    Please Login or Register  to view this content.

    Is there a way to solve this?
    Last edited by anon12398; 03-07-2019 at 06:06 AM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,042

    Re: Custom Format with Numbers and Letters?

    Hi, welcome to the forum

    To best describe or illustrate your problem you would be better off attaching a dummy workbook. The workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,071

    Re: Custom Format with Numbers and Letters?

    Unclear.

    You mention J24 in your first few examples.
    But you haven't listed it in your final output.
    Where would J24 go ?
    QUESTION: If you had J2 where would J2 go in relation to J24 ?

    Output appears to be sort by:
    - first alphabetic letter
    - then if value has a "-" sort by highest number otherwise sort by lowest number
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  4. #4
    Forum Contributor noboffinme's Avatar
    Join Date
    08-29-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003/7/10/13/16/19
    Posts
    1,071

    Re: Custom Format with Numbers and Letters?

    Hi anon12398,

    You could split each character using the 'Text to Columns' feature under the 'Data' tab and then do a Custom sort excluding the '-' character.
    This a bit manual though, if you have lots of rows you could use a Macro if you're familiar with VBA?
    Remember you are unique, like everyone else

  5. #5
    Registered User
    Join Date
    03-07-2019
    Location
    dsntmttr
    MS-Off Ver
    2016pp
    Posts
    3

    Re: Custom Format with Numbers and Letters?

    You mention J24 in your first few examples.
    But you haven't listed it in your final output.
    Woopsie. You are right. Updated he initial post.

    QUESTION: If you had J2 where would J2 go in relation to J24 ?
    J2 comes before J24.

    Output appears to be sort by:
    - first alphabetic letter
    - then if value has a "-" sort by highest number otherwise sort by lowest number
    that's correct.

  6. #6
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,071

    Re: Custom Format with Numbers and Letters?

    Where would an F-2 go in relation to F-2B ?

  7. #7
    Registered User
    Join Date
    03-07-2019
    Location
    dsntmttr
    MS-Off Ver
    2016pp
    Posts
    3

    Re: Custom Format with Numbers and Letters?

    Where would an F-2 go in relation to F-2B ?
    without trailing letter comes before a trailing letter

    Please Login or Register  to view this content.
    Last edited by anon12398; 03-07-2019 at 06:34 AM.

  8. #8
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,071

    Re: Custom Format with Numbers and Letters?

    OK, this works on your example data, and should work for any number in the string up to 100,000.

    Create a Helper column with this formula

    =LEFT(A1,1)&IF(MID(A1,2,1)="-",0,1)&100000-SUMPRODUCT(MID(0&A1, LARGE(INDEX(ISNUMBER(--MID(A1, ROW(INDIRECT("1:"&LEN(A1))), 1)) * ROW(INDIRECT("1:"&LEN(A1))), 0), ROW(INDIRECT("1:"&LEN(A1))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(A1)))/10)

    and sort the data on the helper column

    Formula sorts on
    first letter
    then a 1 or 0 (0 if next character is "-" otherwise 1
    then the number that follows - this is subtracted from 100,000 to provide a reverse order a-3 a-2 a-1 rather than a-1 a-2 a-3


    Not sure about f-2 and f-2b being in right order though if they were to exist together.

    UPDATE: OOps! Doesn't work! Thinking...
    Last edited by Special-K; 03-07-2019 at 06:40 AM.

  9. #9
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,071

    Re: Custom Format with Numbers and Letters?

    This looks better.

    =LEFT(A1,1)&IF(MID(A1,2,1)="-",0,1)&100000+IF(MID(A1,2,1)="-",-1,1)*SUMPRODUCT(MID(0&A1, LARGE(INDEX(ISNUMBER(--MID(A1, ROW(INDIRECT("1:"&LEN(A1))), 1)) * ROW(INDIRECT("1:"&LEN(A1))), 0), ROW(INDIRECT("1:"&LEN(A1))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(A1)))/10)

    I still havent sorted
    F-2 F-2B

  10. #10
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,071

    Re: Custom Format with Numbers and Letters?

    F-2 F-2b problem sorted

    =LEFT(A1,1)&IF(MID(A1,2,1)="-",0,1)&100000+IF(MID(A1,2,1)="-",-1,1)*SUMPRODUCT(MID(0&A1, LARGE(INDEX(ISNUMBER(--MID(A1, ROW(INDIRECT("1:"&LEN(A1))), 1)) * ROW(INDIRECT("1:"&LEN(A1))), 0), ROW(INDIRECT("1:"&LEN(A1))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(A1)))/10)&(RIGHT(A1,1)>="A")*1

    This assumes trailing letters will actually be letters not punctuation characters
    and you wont have

    F-2b and F-2B together

+ 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. Replies: 11
    Last Post: 12-14-2020, 09:46 AM
  2. Custom Formatting in Excel with Letters and Numbers
    By fornie in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-24-2014, 12:48 PM
  3. Replies: 4
    Last Post: 11-04-2012, 08:38 PM
  4. UserForm Textbox Format With Capital Letters and Numbers
    By saucey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-22-2012, 11:38 AM
  5. [SOLVED] Merging Numbers with custom format - how to keep format
    By oddcarout in forum Excel General
    Replies: 3
    Last Post: 08-15-2012, 07:54 PM
  6. Excel custom format with letters and numbers
    By pdrodrig in forum Excel General
    Replies: 1
    Last Post: 06-11-2009, 08:08 AM
  7. Replies: 2
    Last Post: 11-15-2005, 03:40 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