Intermediate / Lesson 06

Clean and combine text

Make imported labels consistent without destroying meaningful identifiers.

~35 minutes6 exercisesSee lesson notes for version and platform support

By the end, you’ll be able to:

  • Clean ordinary spaces and inspect string length
  • Extract fixed-position code segments
  • Combine fields with deliberate separators

Keep the original while you clean

Names and product codes often arrive with inconsistent spacing. Keep a raw column, add a cleaned output and compare examples before replacing the original. A formula cannot decide whether two similar names refer to the same person.

The fictional code SG-0149 has a country prefix, a hyphen and a four-character identifier. Preserve the identifier as text: removing its leading zero changes the code’s presentation and can break a downstream match.

Example worksheet with column letters and row numbers
ABCDE
1Raw nameCodeFirstLastMiddle
2 Maya Chen SG-0149MayaChen
3 Leo Park UK-0208LeoPark

Trim spaces, measure and standardize case

=TRIM(text)=LEN(text)=UPPER(text)=LOWER(text)

text is the source string or cell. TRIM removes leading/trailing ordinary spaces and reduces repeated ordinary spaces between words to one. LEN counts characters, including spaces. UPPER and LOWER change letter case.

=TRIM(A2) returns Maya Chen, and =LEN(TRIM(A2)) returns 9. Excel TRIM does not remove every Unicode whitespace character; nonbreaking spaces from web pages can need additional cleaning. Test a real imported sample.

Extract a segment by position

=LEFT(text, [num_chars])=RIGHT(text, [num_chars])=MID(text, start_num, num_chars)

text is the source. num_chars is how many characters to return; LEFT/RIGHT default to 1 when omitted. MID’s required start_num counts from 1, and its required num_chars gives the segment length.

For B2, =LEFT(B2,2) returns SG, =RIGHT(B2,4) returns 0149, and =MID(B2,4,4) also returns 0149. Fixed positions are reliable only when the code structure is reliable.

Join fields without accidental extra separators

=TEXTJOIN(delimiter, ignore_empty, text1, [text2], ...)=CONCAT(text1, [text2], ...)

delimiter is text inserted between items; ignore_empty controls whether empty cells are skipped; text1 and further text arguments supply cells, ranges or strings. CONCAT joins supplied text without adding a separator automatically.

=TEXTJOIN(" ",TRUE,C2,E2,D2) returns Maya Chen, skipping the empty middle name. =CONCAT(C2," ",D2) produces the same result using an explicit space. Excel’s & operator can also join text.

Check structure rather than assuming it

Try a blank name, an extra space and a code from another country. If codes vary in length or delimiter position, fixed MID arguments can silently extract the wrong segment. Keep a validation flag for unexpected structures and investigate those rows.

LEFT, RIGHT, MID, LEN, TRIM, UPPER and LOWER work in older Excel versions. TEXTJOIN and CONCAT are available in Microsoft 365, Excel 2019 and later and current web Excel. The browser tasks use ordinary English characters; complex Unicode character counting can differ with Excel compatibility settings.

Now make it yours

Give it a try.

Work through each exercise, check your answer and use a hint whenever you need one. Formula tasks check changed inputs, including boundary cases.

0 of 6 exercises complete

Exercise 01 / Formula practice

Clean an ordinary-spaced name

Use TRIM to clean Raw name in A2. Enter the formula for G2.

Example worksheet with column letters and row numbers
ABCDE
1Raw nameCodeFirstLastMiddle
2 Maya Chen SG-0149MayaChen
3 Leo Park UK-0208LeoPark
Exercise 02 / Formula practice

Read the country prefix

Use LEFT to return the first two characters of Code in B2. Enter G3.

Example worksheet with column letters and row numbers
ABCDE
1Raw nameCodeFirstLastMiddle
2 Maya Chen SG-0149MayaChen
3 Leo Park UK-0208LeoPark
Exercise 03 / Formula practice

Preserve the leading zero

Use MID to return the four-character identifier beginning at character 4 of B2. Enter G4.

Example worksheet with column letters and row numbers
ABCDE
1Raw nameCodeFirstLastMiddle
2 Maya Chen SG-0149MayaChen
3 Leo Park UK-0208LeoPark
Exercise 04 / Formula practice

Join a name with an optional middle

Use TEXTJOIN with a single-space delimiter to join First C2, optional Middle E2 and Last D2 in that order. Skip empty cells. Enter G5.

Example worksheet with column letters and row numbers
ABCDE
1Raw nameCodeFirstLastMiddle
2 Maya Chen SG-0149MayaChen
3 Leo Park UK-0208LeoPark
Exercise 05 / Formula practice

Measure after cleaning

Count the characters in A2 after TRIM removes extra ordinary spaces. Enter G6 using LEN.

Example worksheet with column letters and row numbers
ABCDE
1Raw nameCodeFirstLastMiddle
2 Maya Chen SG-0149MayaChen
3 Leo Park UK-0208LeoPark
Exercise 06 / Knowledge check

Choose a stable extraction rule

Codes sometimes have two-character country prefixes and sometimes three. What should you do before applying MID(code,4,4) to every row?

Choose one answer

The bounded practice checker accepts equivalent supported formulas, lowercase function names and text labels, extra spaces, and comma or semicolon separators. Array tasks check the complete result shape and values. It is a teaching tool, not a complete Excel engine. See supported behavior.

Take this with you

Keep raw data, clean deliberately and preserve identifiers as text. Extraction positions must match a verified structure.

Practice in Excel

Download the course workbook, follow the tasks, save your completed .xlsx and check its supported formula tasks here. Native Excel features use a separate review checklist.

Download practice workbook Check my workbook ↗
Technical references and lesson review

Original lesson content. Technical behavior checked against Microsoft documentation. Reviewed 2026-10-16.

Find your next skill