fx Text & Date Functions

LEFT, RIGHT, MID, LEN, TRIM, CLEAN, UPPER/LOWER/PROPER

⏱ 9 min

What you'll learn

  • Extract text with LEFT, RIGHT, MID and FIND, preserving leading zeros.
  • Clean spaces and control characters and review capitalization.
  • Convert extracted years to numbers with VALUE.

Concept

1. Cutting text

Invoice number in A2: INV-2026-0457

Formula Meaning Result
=LEFT(A2, 3) 3 characters from the left INV
=RIGHT(A2, 4) 4 characters from the right 0457
=MID(A2, 5, 4) starting at position 5, take 4 2026
=LEN(A2) total characters 13

Spaces and dashes count as characters too.

2. Dynamic cutting with FIND

When the length isn't fixed, find the position of a separator first. Username from an email in B2 (rahul.sharma@gmail.com):

=LEFT(B2, FIND("@", B2) - 1)   → rahul.sharma

FIND gives the position of "@" (13); we take everything before it.

3. Cleaning spaces — TRIM

" Rahul Sharma " → =TRIM(A2) → "Rahul Sharma"

TRIM removes spaces at the start and end, and reduces multiple spaces between words to one. This fixes many "why is my lookup showing #N/A?" problems.

4. Hidden characters — CLEAN

Data copied from software or websites often contains invisible line breaks and control characters. =CLEAN(A2) removes them. Use both together:

=TRIM(CLEAN(A2))

Web data trap: the "non-breaking space" (CHAR 160) is not removed by TRIM or CLEAN. Replace it first:

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

5. Capitalisation

Formula rahul SHARMA becomes
=UPPER(A2) RAHUL SHARMA
=LOWER(A2) rahul sharma
=PROPER(A2) Rahul Sharma

PROPER capitalises the letter after every non-letter, so o'brien becomes O'Brien but mcdonald's becomes Mcdonald'S. Always check names after using it.

6. Numbers from text are still text

=LEFT("2026ABC", 4) returns "2026" as text (left-aligned). To use it as a number:

=VALUE(LEFT(A2, 4))

Common mistakes

Forgetting that spaces count in LEN and positions. Using TRIM on web data and expecting CHAR(160) to go. Doing maths on LEFT/RIGHT results without VALUE.

Exercises

mediumColumn A has 10 messy names like " aMIT kumar ". Create a clean column with =PROPER(TRIM(A2)). Then from invoice numbers like INV-2026-0457, extract the year as a number and the serial number.
Text Basics B2: =PROPER(TRIM(A2)); fill to row 11. The first name becomes Amit Kumar. C2/D2 can use UPPER/LOWER on B2. For the control-character example in H2 use =TRIM(CLEAN(H2)); for H3 use =TRIM(SUBSTITUTE(H3,CHAR(160)," ")). On Invoices, D2: =VALUE(MID(A2,5,4)) returns numeric 2026; E2: =RIGHT(A2,4) returns text 0457; F2: =LEN(A2) returns 13. G2: =LEFT(B2,FIND("@",B2)-1) returns rahul.sharma. Keep serials as text to preserve zeros.

Quiz

=LEN(" Hi ")?
5
=MID("EXCELWALAA", 6, 5)?
WALAA
Which space does TRIM not remove?
Non-breaking space, CHAR(160)
LEFT, RIGHT, MID, LEN, TRIM, CLEAN, UPPER/LOWER/PROPER · Foundations | ExcelWalaa