Skip to main content

How to sort numbers or texts and remove the duplicate records directly in Excel?

Author Sun Last modified

Sorting and removing duplicate values in Excel can be tricky, especially when duplicates are grouped during sorting. This guide provides step-by-step instructions on how to sort numbers or text while removing duplicates directly using formulas.
A screenshot of a data list containing duplicate numbers to be sorted and deduplicated in Excel

Sort numbers and remove the duplicate ones

Sort texts and remove the duplicate ones


Sort numbers and remove the duplicate ones

To sort numbers and remove duplicates, you need some formulas to help you.

1. Firstly, you need to identify the duplicate rows by using this formula =COUNTIF(A2:A$11,"="&A1), A1 is the first number in the list, A11 is the cell below the last number of the list. Drag auto fill down to fill cells with this formula.
A screenshot showing the COUNTIF formula identifying duplicates in Excel

2. Then in adjacent column, type this formula =IF(B1=0,A1,"") B1 is the first formula cell. Drag the fill handle down to sort the numbers. Duplicates will be displayed as blanks.
A screenshot showing duplicates displayed as blank cells after applying the IF formula in Excel

3. In next column, use =SMALL(C$1:C$10,ROW(C1)-ROW(C$1)+1) to sort numbers from smallest to largest and remove duplicate ones. C1:C10 is the third formula range.
A screenshot showing sorted numbers with duplicates removed using the SMALL formula in Excel

Tip:

1. If you want to sort the numbers from largest to smallest, you can use this formula =LARGE(C$1:C$10,ROW(C1)-ROW(C$1)+1).
A screenshot showing sorted numbers in descending order using the LARGE formula in Excel

2. You can apply the Error Condition Wizard of Kutools for Excel, select Any error value from Error types drop down list to convert errors to blanks or message as you need. (Free Download Kutools for Excel Now!)
A screenshot of the Kutools for Excel Error Condition Wizard


Sort texts and remove the duplicate ones

If you want to sort text and remove the duplicate values, you will also need some formulas.

1. Firstly, add a series of numbers adjacent to the text list.
A screenshot showing a text list with duplicate entries in Excel

2. In the column C, type this formula =IF(COUNTIF(B12:B$21,B12)=1,B12,"") (B12:B21 is the text range) to extract the unique texts.
A screenshot showing unique text values extracted using COUNTIF in Excel

3. In the column D, type this =COUNTIF(C$12:C$21,"<"&C12) to sort the unique texts. In this case, duplicates will be displayed as zeros.
A screenshot showing unique text sorted with duplicates shown as zeros using COUNTIF in Excel

4. In column E, type this formula =MATCH(A12,D$12:D$21,0), the zeros will be displayed as errors. A12 is the first number in the series, D12:D21 is the third formula range.
A screenshot showing MATCH formula results for unique text sorting in Excel

5. In column F, type this formula =INDEX(B$12:B$21,E12), B12:B21 is the text range, E12 is the first cell of previous formula range. Now the duplicates are shown as errors, and only unique texts are sorted.
A screenshot showing unique texts sorted using the INDEX formula in Excel

Tip: You also can apply the Error Condition Wizard of Kutools for Excel to convert only the #N/A error value to blanks. (Free Download Kutools for Excel Now!)
A screenshot of the Kutools for Excel Error Condition Wizard for handling #N/A errors

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!