+ Reply to Thread
Results 1 to 14 of 14

Sorting numbers and text together

Hybrid View

  1. #1
    Registered User
    Join Date
    03-28-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    38

    Question Sorting numbers and text together

    I have a column which has years in it. The problem is, some of them are entered as a range and some as a single year.
    e.g. 2000, 2001-05, 2003-05, 2005, 2010, 2010-12

    I am trying to sort this column in such a way that both the ranges and the single years are arranged in order. But, excel sorts the single years (stored as numbers) and the range (stored as text) separately.

    How can i arrive at a solution for this issue?

  2. #2
    Valued Forum Contributor abduljaleel.mca's Avatar
    Join Date
    02-13-2013
    Location
    Chennai, India
    MS-Off Ver
    MS 365 Business
    Posts
    326

    Re: Sorting numbers and text together

    Hi,

    Assume your data is in column A then put this formula in column B and copy down as required.

    =RIGHT(A1,4)
    .

    Copy Column B data and Paste / Special / Values over the top. Sort Column A:B with Sort by Column B.

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

    Re: Sorting numbers and text together

    Quote Originally Posted by abduljaleel.mca View Post
    Hi,

    Assume your data is in column A then put this formula in column B and copy down as required.

    =RIGHT(A1,4)
    .

    Copy Column B data and Paste / Special / Values over the top. Sort Column A:B with Sort by Column B.
    Given 2001-05, 2003-05 will produce 1-05 and 3-05.
    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
    Valued Forum Contributor abduljaleel.mca's Avatar
    Join Date
    02-13-2013
    Location
    Chennai, India
    MS-Off Ver
    MS 365 Business
    Posts
    326

    Re: Sorting numbers and text together

    Yes, you are right. It should be
    =LEFT(A1,4)

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Sorting numbers and text together

    An alternative, assuming data start in A1:

    =TEXT(A1,"###")

    in B1 and copy down. Then select all data and use DATA/SORT/sort by column B/Treat text and numbers separately
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  6. #6
    Registered User
    Join Date
    03-28-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    38

    Re: Sorting numbers and text together

    @abduljaleel.mca: Your idea was brilliant!
    The formula =Left (A1,4) took the first 4 digits (starting from left) in column A. Hence, I got a column with all single years (the year ranges become single years e.g. 2010-12 became 2010). This way, I was able to sort my column perfectly!

    @Glenn Kennedy: Your idea was exactly what I needed! Your formula converted all the years (both the range and single) as text, so that, I was able to sort them without any hitch!

    Thank you guys!

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Sorting numbers and text together

    You're welcome and thanks for the feedback.

  8. #8
    Registered User
    Join Date
    03-28-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    38

    Re: Sorting numbers and text together

    I think I was wrong when I said that your formula just changed the numbers to text. It appears to be doing something more as well!

    Numbers can be easily changed to text (Format cells > Text). But, that did not help me with sorting (the single years get sorted first and then the range years).

    Can you explain how is your formula different from simply changing the format to text?

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Sorting numbers and text together

    The TEXT(A1,"###") buit DOES format everything as text. The key is the sort option - sort numbers and numbers stored as text separately. Excel would prefer to treat number-like strings as numbers. This option forces it to treat everything as text (everything is text, of course), so it returns an alphabetically sorted list.

  10. #10
    Registered User
    Join Date
    03-28-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    38

    Re: Sorting numbers and text together

    While I do the sorting, the option "Sort numbers and numbers stored at text separately" does not appear at all (The sort warning box does not appear!). But still, when I use your formula, excel sorts them perfectly, but falters when I use the 'Format cells > Text' method.

    I am using Excel 2016.
    Last edited by Bradex; 08-03-2016 at 11:49 AM.

  11. #11
    Registered User
    Join Date
    03-28-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    38

    Re: Sorting numbers and text together

    I confirmed it by using =istext(a1)

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Sorting numbers and text together

    I don't have Excel 2016 so I can't see what it does... But, hey, if it works!!

  13. #13
    Registered User
    Join Date
    03-28-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    38

    Re: Sorting numbers and text together

    I think I found the reason!

    'Format cells > Text' does not change a number which has been already entered to text. The cell has to be formatted 'before' entering the number. But your formula does change the number to text. That's why it works!

    I think that the 'sort warning box' has been removed in Excel 2016.

  14. #14
    Registered User
    Join Date
    03-28-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    38

    Re: Sorting numbers and text together

    How is TEXT(A1,"###") different from TEXT(A1,"0")?

+ 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. Sorting Text That Contains Numbers
    By badAdjective in forum Excel General
    Replies: 3
    Last Post: 12-27-2012, 09:47 PM
  2. Sorting text and numbers
    By jaws1 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-03-2012, 05:43 PM
  3. [SOLVED] Excel 2007 : Help with Sorting numbers and text
    By suzyblue in forum Excel General
    Replies: 6
    Last Post: 05-30-2012, 01:44 PM
  4. Sorting Numbers containing Text
    By Taco2007 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2007, 10:30 AM
  5. Sorting numbers as Text
    By David M. in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 07-25-2006, 12:50 PM
  6. [SOLVED] SORTING TEXT AND NUMBERS
    By jstephenson in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-10-2006, 04:50 PM
  7. sorting text & numbers
    By billjr in forum Excel General
    Replies: 3
    Last Post: 08-04-2005, 03:05 PM

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