Course / Working with Text

Cleaning up messy text

Fix stray spaces, random capitals and inconsistent codes in imported data. Intermediate · 5 min · TRIM, PROPER, UPPER, LOWER, SUBSTITUTE

Data exported from other systems is rarely tidy. Names arrive in CAPITALS, emails in a mix of cases, and stray spaces hide where you can't see them. Fixing it by hand is slow and easy to get wrong. Five functions do most of the work:

Clean the data with formulas in new columns, and keep the original next to it so you can always check your work.

Steps

  1. The imported names in column A have extra spaces at the start, at the end and in the middle. In D2:D8, tidy them with =TRIM(A2).

  2. Now fix the capitals too. Change D2:D8 so that TRIM sits inside PROPER: =PROPER(TRIM(A2))

  3. Email addresses don't care about capitals, but mixed case looks messy and trips up duplicate checks. In E2:E8, convert each email to lowercase.

  4. Booking references should be in capitals. In F2:F8, convert them with UPPER.

  5. Remove those inner spaces by substituting every space with nothing (""). Change F2:F8 to =SUBSTITUTE(UPPER(C2), " ", "")

Remember

Previous: Splitting text at a character · Next: Formatting numbers in text with TEXT