AaIntermediate

Excel text function practice: TRIM, LEFT, MID and more

Real data is messy. These exercises use an exported customer list with extra spaces and random capitals. You'll clean names with TRIM and PROPER, pull pieces out of codes with LEFT and MID, and join text together.

11 exercises0/11
Start practicing →

Try it yourself

A live spreadsheet. Type a formula and press Enter to check it.

Exercise 1 of 11TRIMPROPER

Clean the name in A2: remove the extra spaces and capitalize it properly.

Write your formula in the green cell, G2.

customer-export.xlsx
fx
1Full nameEmailPhoneOrder code
2 emma JOHNSON [email protected](555) 201-4433NW-2026-0187Clean name
3liam o'brien[email protected]555.388.1902CT-2025-0942
4OLIVIA chen [email protected]555-647-2210FB-2026-0033
5noah patel[email protected](555) 903 7751NW-2026-0451
6Sofia Martinez[email protected]555 412 0098AW-2024-1120
7
8
9
10

Click a cell to add it to your formula, drag to select a range, or click a column letter for the whole column.

All 11 text exercises

  1. 1

    Clean up a name

    Free

    Clean the name in A2: remove the extra spaces and capitalize it properly.

  2. 2

    Store code

    Free

    Get the 2-letter store code from the start of the order code in D3.

  3. 3

    Text from the end

    Premium

    Get the last 4 digits of the order code in D4.

  4. 4

    Count characters

    Premium

    How many characters are in the phone number in C5, including spaces and brackets?

  5. 5

    Pull out the year

    Premium

    Extract the year (the 4 digits in the middle) from the order code in D2.

  6. 6

    Email domain

    Premium

    Get the domain from the email in B4: everything after the @.

  7. 7

    Text before a character

    Premium

    Get the part of the email in B6 that comes before the @.

  8. 8

    Replace characters

    Premium

    Reformat the phone number in C3 from 555.388.1902 to 555-388-1902.

  9. 9

    Build a label

    Premium

    For row 5, build a label like AW-2024-1120 - Sofia Martinez: the order code, a space, a dash, a space, then the clean name.

  10. 10

    First name from a messy cell

    Premium

    Get the first name from A5, cleaned up and capitalized: Noah.

  11. 11

    Join a list

    Premium

    Join all five order codes in D2:D6 into one cell, separated by a comma and a space.

The text functions, with examples

Every example runs on customer-export.xlsx, the same sheet the exercises use, and the results are calculated from that data.

  • TRIM

    Removes spaces at the start and end and squeezes repeated spaces between words down to one.

    TRIM(text)

    Example

    =TRIM(A2)returnsemma JOHNSON
  • PROPER

    Capitalizes the first letter of each word and lowercases the rest. Wrap TRIM inside it to clean names in one go.

    PROPER(text)

    Example

    =PROPER(TRIM(A2))returnsEmma Johnson
  • LEFT

    Returns the first characters of a text. RIGHT returns the last ones.

    LEFT(text, [num_chars])

    Example

    =LEFT(D2, 2)returnsNW
  • MID

    Returns characters from the middle of a text: give the start position and how many.

    MID(text, start_num, num_chars)

    Example

    =MID(D2, 4, 4)returns2026
  • TEXTAFTER

    Returns everything after a delimiter, like the domain after the @ in an email. TEXTBEFORE does the opposite. In Microsoft 365 and Excel 2024; older versions need MID and FIND.

    TEXTAFTER(text, delimiter, [instance_num])

    Example

    =TEXTAFTER(B2, "@")returnsnorthwind.com

Common mistakes

  1. 1

    Expecting TRIM to remove every space

    Text copied from websites often contains non-breaking spaces, which TRIM leaves alone. Swap them for normal spaces first: =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).

  2. 2

    Forgetting that extracted digits are text

    MID returns the text "2026", not the number 2026. A SUM over a column of them gives 0, and a lookup against real numbers finds nothing. Wrap the result in VALUE when you need a number.

  3. 3

    Trusting PROPER with every name

    PROPER capitalizes after any non-letter, so liam o'brien becomes Liam O'Brien. But it turns mcdonald into Mcdonald. Check names with prefixes like Mc and Mac by hand.