Get instant live expert help with Excel or Google Sheets
“My Excelchat expert helped me in less than 20 minutes, saving me what would have been 5 hours of work!”

Post your problem and you’ll get expert help in seconds.

Your message must be at least 40 characters
Our professional experts are available now. Your privacy is guaranteed.

How to Sort Text and Number with a Formula

We can sequentially arrange text and numbers in excel based on ranks assigned to the text and numbers in another cell. We can do this with the COUNTIF, ISTEXT, INDEX, and MATCH Functions. This step by step tutorial will assist all levels of Excel users in sorting text and numbers using a formula.

Figure 1: Result of Sequentially Sorted Data

Formula

Ranking formula: =COUNTIF(Data,"<="&A4)+(COUNT(Data)*ISTEXT(A4))

Sorting formula: =INDEX(Data,MATCH(ROWS($C$4:C4),Rank,0))

Setting up the Data

  • We will input the numeric and text values into the cells as shown in figure 2

Figure 2: Setting up the Data

  • We must note that Data and Rank are named ranges. This means that Cell A4 to Cell A10 is collectively named as Data and Cell B4 to Cell B10 is collectively named as Rank. To do this, highlight Cell A4 to Cell A10 and go to the position of G12 (REFER TO FIGURE 2) on your spreadsheet. Click on it and name it as Data. Ensure to press the enter key. Do the same for Rank.

Ranking the Data

  • We will click on Cell B4
  • We will insert the formula and press enter: =COUNTIF(Data,"<="&A4)+(COUNT(Data)*ISTEXT(A4))

Figure 3: Ranking the Data

  • We will click on the fill handle and drag down to copy the formula into the other cells

Figure 4: Ranked Data

Sorting the Data Sequentially

  • We will click on Cell C4
  • We will insert the formula and press enter: =INDEX(Data,MATCH(ROWS($C$4:C4),Rank,0))

Figure 5: Sorting the Data Sequentially

  • We will click on the fill handle and drag down to copy the formula into the other cells

Figure 6: Result of Sequentially Sorted Data

Explanation

When ranking the data, the COUNTIF section of the formula is suitable for ranking only all text values or all numeric values. To accommodate a count of the numeric values into a single formula, the COUNT FUNCTION is used.

The COUNT FUNCTION gets the COUNT of numeric values in the data. The value is then multiplied by the logical result of ISTEXT. ISTEXT detects if the value is a text or number and returns TRUE or FALSE.

Handling Blank Cells

Assuming Cell A7 is a blank cell, we can still rank the values with the formula discussed above. However, zero will be the assigned rank to the empty cell. To ensure that this zero does not interfere with the sorted values, we will insert the formula below into Cell C4, PRESS ENTER and use the fill handle to copy the formula into the remaining cells.

=IFERROR(INDEX(Data,MATCH(ROWS($C$4:C4),Rank,0)),"")

Figure 7: Handling Blank Cells

Note

  • To sort data that contains duplicate values, use the formula below TO RANK THE DATA and adhere to the aforementioned steps TO SORT THE DATA

=COUNTIF(Data,"<"&A4)+(COUNT(Data)*ISTEXT(A4))+COUNTIF($A$4:A4,A4)

Instant Connection to an Expert through our Excelchat Service

Most of the time, the problem you will need to solve will be more complex than a simple application of a formula or function. If you want to save hours of research and frustration, try our live Excelchat service! Our Excel Experts are available 24/7 to answer any Excel question you may have. We guarantee a connection within 30 seconds and a customized solution within 20 minutes.

Did this post not answer your question? Get a solution from connecting with the expert.

Another blog reader asked this question today on Excelchat:
Solution examples
I need a formula to compare the data in two columns and then export the mismatched data in the 3rd column
Solved by S. Q. in 20 mins
I need a formula that will pull items from a certain column, depending on two other criteria related to two other columns, and print out every instance that matches all of the above once and only once, and stop printing when all instances are printed. Currently have been relying on this for half of the job (printing one, and only one, instance of every unique element), but have not been able to incorporate the other two criteria: =ArrayFormula(index(RawData!$E$2:$E$500000, match(0, COUNTIFS($C$1:$C12,RawData!$E$2:$E$5000),0)))
Solved by I. F. in 60 mins
Trying to get the sheet name in the formula below to change based on the text in a specific cell. So in the example below, if the text in cell A1 is currently "Sheet 1" and i change it to "New Sheet Name", the formula below would read that and replace 'Sheet 1'! with 'New Sheet Name'! =IFERROR(INDEX('Sheet 1'!$G$8:$G$2000, MATCH(0,COUNTIF(O$2:O3, 'Sheet 1'!$G$8:$G$2000), 0)),"")
Solved by E. W. in 31 mins
I need to sum the number of hours per month one of three halls are being rented
Solved by A. F. in 60 mins
I cannot enter this formula into Excel. I get an error message asking for an apostrophe?IF($S2=0,"",IF($S2>0,RANK($S2,$S$2:$S$8000),RANK($S2,$S$2:$S$8000-COUNTIF($S$2:$S$8000,0)))
Solved by B. W. in 20 mins

Leave a Comment

avatar

Subscribe to Excelchat.co

Get updates on helpful Excel topics

Subscribe to Excelchat.co

Did this post not answer your question?
Get a solution from connecting with the expert

Another blog reader asked this question today on Excelchat:

Post your problem and you’ll get expert help in seconds.

Your message must be at least 40 characters
Our professional experts are available now. Your privacy is guaranteed.
Trusted by people who work at
Amazon.com, Inc
Facebook, Inc
Accenture PLC
Siemens AG
Macy's
The Allstate Corporation
United Parcel Service
Dell Inc