Tidy text with TRIM, CLEAN, UPPER and PROPER
Text functions6 min
Builds on Copy a formula down a column.
Sign-ups for the customer evening came in through a web form, and people typed their names their own way: in capitals, in lowercase, with spaces before and after. Before the name badges are printed, every name needs the same look.
How it works
A space is a character like any other. Lyon and Lyon with a space at the end are different texts to Excel, so a lookup or a COUNTIF treats them as different, even though they look the same on screen.
TRIM removes the spaces at the start and the end of a text, and shrinks every run of spaces between words to one. CLEAN removes characters that don't print, such as a line break that came along with a name pasted from an email. Neither one touches the letters.
UPPER, LOWER and PROPER change only the capitals. For aNNE-marie o'BRIEN:
| Row | A | B |
|---|---|---|
| 1 | Function | Returns |
| 2 | UPPER | ANNE-MARIE O'BRIEN |
| 3 | LOWER | anne-marie o'brien |
| 4 | PROPER | Anne-Marie O'Brien |
PROPER capitalizes the first letter of each word and any letter that follows a character other than a letter, which is why M and B get capitals too.
Each function returns a tidy copy and leaves the original alone, so you write it in a new column. To do two jobs at once, put one function inside the other. Excel works from the inside out: in PROPER(TRIM(...)), TRIM goes first. When a cell may hold line breaks, put CLEAN inside TRIM, so that TRIM also tidies any spaces the breaks were next to.
Example
The delivery list has nORTH cAROLINA in F2, typed with Caps Lock on.
=PROPER(TRIM(F2))It returns North Carolina.
Common mistakes
=PROPER(F2)fixes the capitals but keeps the spaces. Put TRIM inside it.- PROPER doesn't know names:
MCDONALDbecomes Mcdonald, andVAN DER BERGbecomes Van Der Berg. Check names like these by eye. - The tidy column is still made of formulas. Before you delete the original column, copy the tidy one and paste it as values.
In short
- Spaces are characters, so a stray one stops a match.
- TRIM removes extra spaces, and CLEAN removes characters that don't print.
- UPPER, LOWER and PROPER set the capitals. Nest them around TRIM.
Practice
4 exercises · free with an account