ShareYourGroupShareYourGroupExcel Formulas

Guides

Cleaning and splitting text in Excel

Data rarely arrives clean. Names come in capitals, with double spaces. Numbers arrive as text. A code and a description share one cell. Before any totals or lookups can be trusted, the text has to be put right. This page is a set of recipes for that, using formulas that work in every recent version of Excel.

Sample sheet: Text as people really type it: stray spaces, mixed capitals, codes with dashes.
ABCD
1Full nameEmailCodeAmount as text
2  asha   verma asha.verma@example.comPB-10-12341,250
3RAVI KUMARravi@example.orgDL-08-0042300
4meena gillmeena.gill@example.comMH-12-9876 45.50 
5Kabir Khankabir@example.netRJ-14-000712 kg

Work in a spare column

Cleaning formulas do not change the original cell. They give their result somewhere else. The routine is always the same.

  1. Write the formula in an empty column beside the data.
  2. Copy it down.
  3. When the results look right, copy them, and use Paste Special, Values over the original column.
  4. Delete the helper column.

Keep a copy of the raw data on another sheet until you are sure.

1. Remove extra spaces

TRIM removes spaces at both ends and squeezes runs of spaces between words down to one. The two lengths show how many characters went.

If TRIM appears to do nothing, the spaces are probably non-breaking spaces from a web page: =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).

2. Fix the capitals

PROPER gives each word a capital. Check its results on names with apostrophes and on abbreviations, which it gets wrong.

3. Split a full name

First name: everything before the first space. Surname: everything after it.

FIND locates the space, and LEFT and MID cut on either side of it. The third formula trims first, which is needed when the cell starts with spaces.

For a one-time job, two tools are quicker than formulas.

Names with three or more parts need a decision about what counts as the surname. The last word is =TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",50)),50)), a well-known trick that pads every space out to fifty and takes the last fifty characters.

4. Split a code into its parts

When every code has the same layout, the positions are fixed. The pieces are text. The last formula turns the serial into a number.

5. Split an email address

6. Join columns

The & sign joins pieces. TEXTJOIN joins a whole range with a separator and skips empty cells. See also CONCAT.

7. Remove or replace characters

SUBSTITUTE swaps one piece of text for another wherever it occurs. Replacing with "" deletes.

8. Turn text into real numbers

Numbers stored as text will not add up.

The SUM of the text column is zero. VALUE converts each entry, after any unit has been stripped. For a whole column at once, select it and use the warning sign's Convert to Number, or Data, Text to Columns, Finish.

9. Find what is wrong

Before cleaning, find out which rows need it.

Put one in a helper column and filter for the rows that fail.

10. Find duplicates

After cleaning, repeated entries become visible, because "Asha Verma" and " asha verma" are now the same. =COUNTIF($A$2:$A$100,A2)>1 flags every value that occurs more than once. See COUNTIF. The Remove Duplicates command on the Data tab deletes the extra rows.

An all-in-one cleaning formula

For names from an untidy source:

=PROPER(TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," "))))

Reading from the inside out: turn non-breaking spaces into ordinary ones, remove non-printing characters, trim the spaces, and fix the capitals.

A sensible order of work

  1. Keep the original.
  2. Trim spaces first. Many other problems disappear with them.
  3. Fix the case.
  4. Split or join columns.
  5. Convert text numbers and text dates.
  6. Check lengths and formats.
  7. Look for duplicates.
  8. Paste the results as values and remove the helper columns.

Things formulas should not do

Every result on this page was calculated in Microsoft Excel (version 16.0, build 20326) on 12 November 2026, not typed by hand.

This is an independent help site. It is not connected with or approved by Microsoft. Excel and Microsoft 365 are trademarks of Microsoft Corporation, named here only to say which program a formula is for. The people and figures in the sample sheets are made up.