New: 6 free SQL practice datasets with 300+ questions — try the SQL Compiler →
Excel

Excel Text Functions: LEFT, MID, TEXTJOIN, TRIM

Excel text functions explained: LEFT, MID, RIGHT, FIND, SUBSTITUTE, TRIM and TEXTJOIN, how to split a name or email and clean data, with real results.

Upskly AI Team September 27, 2026 12 min read
Excel Text Functions: LEFT, MID, TEXTJOIN, TRIM

Text functions in Excel take a piece of text, such as a name, a product code or an email address, and cut it up, search it, clean it or join it with others. LEFT, MID and RIGHT take characters out of a text, FIND tells you where something is, SUBSTITUTE replaces it, TRIM cleans it, and TEXTJOIN or & glues pieces together. Text is written inside double quotes in a formula, for example "Pune".

They are what you reach for when data arrives in the wrong shape: a full name in one cell that must be two, codes with a prefix to strip, or customer names with stray spaces. Every result below was produced by running the formula in Microsoft Excel.

In this guide

The short version

  • LEFT(text, n), RIGHT(text, n) and MID(text, start, n) cut out characters. They always return text, even when the piece looks like a number.
  • FIND is case sensitive, SEARCH is not and accepts wildcards. Both return #VALUE! when nothing is found.
  • SUBSTITUTE replaces by matching text, REPLACE replaces by position.
  • TRIM removes extra spaces but not the non-breaking space that web data often contains.

LEN, LEFT, RIGHT and MID

LEN(text) counts characters, spaces included. LEFT(text, n) takes the first n characters, RIGHT(text, n) the last n, and MID(text, start, n) takes n characters beginning at position start. A1 holds the invoice code INV-2024-0042:

Cutting up INV-2024-0042
FormulaExcel showsWhy
=LEN(A1)1313 characters including the two hyphens
=LEFT(A1,3)INVthe first three characters
=RIGHT(A1,4)0042keeps the leading zeros
=MID(A1,5,4)2024start at character 5 and take 4
=LEFT(A1,3)&"/"&RIGHT(A1,4)INV/0042& joins pieces together
=RIGHT(A1,4)+1430042 is converted to a number for the addition
=LEFT(12345,2)12shown as 12, but it is text
=ISNUMBER(LEFT(12345,2))FALSEtext, not a number
=ISNUMBER(–LEFT(12345,2))TRUEthe double minus turns it into a real number

FIND and SEARCH: locate text

FIND(what, where) returns the position of the first match, counting from 1. SEARCH does the same but ignores upper or lower case and understands the wildcards ? (any one character) and * (any run of characters). If the text is not there, both return #VALUE!. Combined with LEFT and MID, they split text at a marker such as @:

A1 holds ravi@upskly.com
FormulaExcel showsWhy
=FIND("@",A1)5the @ is the 5th character
=LEFT(A1,FIND("@",A1)-1)ravieverything before the @
=MID(A1,FIND("@",A1)+1,99)upskly.comeverything after the @ (99 is just a big enough length)
=FIND("V","ravi")#VALUE!FIND is case sensitive: no capital V in ravi
=SEARCH("V","ravi")3SEARCH ignores case
=SEARCH("r?v","ravi")1? stands for any one character
=IFERROR(FIND("#",A1),"not found")not foundwrap it in IFERROR when the text may be missing

Splitting a name or an email

The classic job: a full name in one cell, first and last names wanted in two. Find the space, take what is left of it and what is right of it:

A1 holds Asha Verma
FormulaExcel showsWhy
=LEFT(A1,FIND(" ",A1)-1)Ashafirst name: everything before the space
=MID(A1,FIND(" ",A1)+1,99)Vermalast name: everything after the space
=LEFT(A1,1)&". "&MID(A1,FIND(" ",A1)+1,99)A. Vermainitial plus last name
=TEXTBEFORE(A1," ")AshaMicrosoft 365 only: same result, no arithmetic
=TEXTAFTER(A1," ")VermaMicrosoft 365 only

In Microsoft 365 there is also TEXTSPLIT, which splits a text into several cells at once. It needs empty cells to its right and below, because the result spills:

A3 holds a TEXTSPLIT formula and spills into B3 and C3

ABC
1Asha Verma Pune
2
3AshaVermaPune

Only A3 holds a formula

ABC
1Asha Verma Pune
2
3=TEXTSPLIT(A1,” “)VermaPune

Data, Text to Columns and Flash Fill (Ctrl + E) do the same job without formulas. Text to Columns is fixed once you run it, while formulas update when the source changes. Check Flash Fill results, since it works by guessing your pattern.

SUBSTITUTE and REPLACE

SUBSTITUTE(text, old, new, [instance]) replaces text it finds, all matches or only the nth one, and it is case sensitive. REPLACE(text, start, length, new) swaps the characters at a position, whatever they are:

Replacing text
FormulaExcel showsWhy
=SUBSTITUTE(A1,"-","/")2024/05/17every hyphen in 2024-05-17 becomes a slash
=SUBSTITUTE(A2,"-","",2)a-bc-donly the second hyphen is removed
=REPLACE(A3,5,4,"2025")INV-2025-0042characters 5 to 8 of INV-2024-0042 are replaced
=SUBSTITUTE(A4,"apple","X")Apple Xcase sensitive: the capital-A Apple is left alone
=SUBSTITUTE(A1,"-","")+020240517removing the hyphens gives text that + turns into the number 20240517

TRIM, CLEAN and changing case

Imported data is often messy. TRIM removes leading and trailing spaces and reduces runs of spaces inside the text to one. CLEAN removes line breaks and other non-printing characters. UPPER, LOWER and PROPER change case. Here A1 has extra spaces, A2 has a non-breaking space between the names, A3 contains a line break, A4 has mixed case and A5 is a name with an apostrophe:

Cleaning and changing case
FormulaExcel showsWhy
="["&TRIM(A1)&"]"[Asha Verma]spaces at both ends and doubled spaces are gone (brackets show the ends)
=LEN(A1)1616 characters before cleaning
=LEN(TRIM(A1))1010 after TRIM
=LEN(A2)10Asha, a non-breaking space and Verma
=LEN(TRIM(A2))10TRIM changed nothing: it does not touch the non-breaking space
=LEN(TRIM(SUBSTITUTE(A2,CHAR(160)," ")))10swap the non-breaking space for a normal one first
=LEN(A3)3a, the line break and b
=LEN(CLEAN(A3))2CLEAN removed the line break
=UPPER(A4)ASHA VERMA
=LOWER(A4)asha verma
=PROPER(A4)Asha Vermafirst letter of each word in capitals
=PROPER(A5)O'Neil McdonaldPROPER capitalises after the apostrophe and misses the Mc rule

The non-breaking space, CHAR(160), is the most common reason why a cleaned value still does not match. It looks like a space, but TRIM and a search for a normal space both miss it:

A1 holds Asha, a non-breaking space, then Verma
FormulaExcel showsWhy
=FIND(" ",A1)#VALUE!no normal space in the text
=FIND(CHAR(160),A1)5the non-breaking space is at position 5
=A1="Asha Verma"FALSEso it does not equal the text typed with a normal space
=SUBSTITUTE(A1,CHAR(160)," ")="Asha Verma"TRUEafter SUBSTITUTE it does

Joining text: &, CONCAT and TEXTJOIN

The & operator joins texts. CONCAT joins pieces and ranges. TEXTJOIN(delimiter, ignore_empty, range) joins a whole range with a separator between the items, and can skip empty cells. CONCAT and TEXTJOIN need Excel 2019 or Microsoft 365. Here A1:B4 hold names and marks, and row 5 is empty:

Joining names
FormulaExcel showsWhy
=A1&" scored "&B1Asha scored 82
=CONCAT(A1," – ",B1)Asha – 82
=TEXTJOIN(", ",TRUE,A1:A5)Asha, Ravi, Meera, JohnTRUE means skip empty cells
=TEXTJOIN(", ",FALSE,A1:A5)Asha, Ravi, Meera, John, FALSE keeps the empty cell, leaving a stray separator at the end
=TEXTJOIN(", ",TRUE,IF(B1:B4>=50,A1:A4,""))Asha, Meeranames of students with 50 or more
=TEXTJOIN(", ",TRUE,IF(B1:B4>=50,A1:A4))Asha, FALSE, Meera, FALSEwithout the empty text as the false value, IF puts the word FALSE in the list

Counting characters and words

Excel has no built-in word counter, but the difference between the length of a text and the length with the target removed tells you how many times it occurs. A1 holds the quick brown fox with a double space, A2 holds banana and A3 holds Banana:

Counting with LEN and SUBSTITUTE
FormulaExcel showsWhy
=LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1)," ",""))+14words: count the spaces after TRIM, then add one
=LEN(A2)-LEN(SUBSTITUTE(A2,"a",""))3how many a in banana
=LEN(A3)-LEN(SUBSTITUTE(A3,"a",""))3SUBSTITUTE is case sensitive: the capital B does not matter, and the count is still 3 here
=(LEN(A3)-LEN(SUBSTITUTE(LOWER(A3),"a","")))3lowering the case first makes the count case-insensitive
=LEN(A2)-LEN(SUBSTITUTE(A2,"an",""))4for a longer target the difference is 4 characters, not 2 occurrences
=(LEN(A2)-LEN(SUBSTITUTE(A2,"an","")))/LEN("an")2divide by the length of the target

A few more worth knowing

A1 = abc, A2 = ABC, A3 = the text 12.5, A4 = 40
FormulaExcel showsWhy
=EXACT(A1,A2)FALSEEXACT is the case-sensitive comparison
=A1=A2TRUEthe = operator ignores case
=REPT("*",5)*****repeat a text
=REPT("|",A4/10)||||a bar made of characters, one per 10 units
=VALUE(A3)+113.5VALUE converts text that looks like a number
=TEXT(A3,"0.00")12.50format as text
=UPPER(LEFT(A1,1))&MID(A1,2,99)Abccapitalise only the first letter of the text
=CODE("A")65character code of A
=CHAR(66)Bthe character with code 66

Common mistakes

Mistake 1: forgetting that the pieces are text

LEFT, MID and RIGHT return text even when the piece looks like a number, so SUM ignores it. Convert with VALUE() or -- when you need to calculate.

Mistake 2: a hidden non-breaking space

If TRIM seems to do nothing, or a lookup fails for a value that looks identical, test with LEN before and after. If the length does not drop, look for CHAR(160).

Mistake 3: hard-coding the position

=LEFT(A1,4) works only while every first name has four letters. Find the marker with FIND and calculate the length from it, as in the splitting examples.

Mistake 4: FIND on text that may be missing

When the marker is not in the text, FIND returns #VALUE! and so does everything built on it. Wrap it: IFERROR(..., "").

Cheat sheet

Text functions cheat sheet
TaskFormulaNote
First n characters=LEFT(A1, n)returns text
Last n characters=RIGHT(A1, n)
From the middle=MID(A1, start, n)start counts from 1
Position of a character=FIND("@", A1)case sensitive; SEARCH is not
Text before a marker=LEFT(A1, FIND(" ", A1) – 1)or TEXTBEFORE in Microsoft 365
Text after a marker=MID(A1, FIND(" ", A1) + 1, 99)or TEXTAFTER in Microsoft 365
Replace by matching=SUBSTITUTE(A1, "-", "")case sensitive
Replace by position=REPLACE(A1, 5, 4, "2025")
Remove extra spaces=TRIM(A1)not CHAR(160)
Join with a separator=TEXTJOIN(", ", TRUE, A1:A9)Excel 2019 or 365
Count a character=LEN(A1)-LEN(SUBSTITUTE(A1, "a", ""))
Count words=LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1), " ", ""))+1

Try it yourself

Work out each answer first, then open the solution.

1. A column holds email addresses. Write a formula that returns the domain, the part after the @, and test it on two addresses.

Show solution
A1 and A2 hold two addresses
FormulaExcel shows
=MID(A1,FIND("@",A1)+1,99)upskly.com
=MID(A2,FIND("@",A2)+1,99)example.org

Find the @, then take everything after it. The 99 is only a length that is longer than any domain.

2. A1 holds INV-2024-0042. Return INV/0042, and separately return the code with all hyphens removed.

Show solution
A1 holds INV-2024-0042
FormulaExcel shows
=LEFT(A1,3)&"/"&RIGHT(A1,4)INV/0042
=SUBSTITUTE(A1,"-","")INV20240042

3. Count the words in a sentence held in A1.

Show solution
A1 holds Data Analysis With Excel
FormulaExcel shows
=LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1)," ",""))+14

Count the spaces (length with spaces minus length without) and add one. TRIM first, so extra spaces are not counted.

4. A1 holds the text of a 16-digit card number. Show only the last four digits, and replace the rest with stars.

Show solution
A1 holds the text 1234567812345678
FormulaExcel shows
=REPT("*",LEN(A1)-4)&RIGHT(A1,4)************5678

Repeat a star for every character except the last four, then join the last four. Card numbers are 16 digits, so store them as text in the first place (a number would lose its last digit).

Frequently asked questions

How do I extract text from a cell in Excel?

Use LEFT(text, n) for the first characters, RIGHT(text, n) for the last ones and MID(text, start, n) for characters from the middle. Combine them with FIND to cut at a marker such as a space or @.

What is the difference between FIND and SEARCH in Excel?

FIND is case sensitive and takes no wildcards. SEARCH is not case sensitive and accepts ? and *. Both return #VALUE! when the text is not found.

What is the difference between SUBSTITUTE and REPLACE?

SUBSTITUTE replaces text that matches, anywhere it appears. REPLACE replaces the characters at a given position and length, whatever they are.

Why is TRIM not removing spaces in Excel?

The spaces are probably non-breaking spaces (CHAR(160)), which come from web pages. Use TRIM(SUBSTITUTE(A1, CHAR(160), " ")).

How do I combine text from several cells in Excel?

Use & for a few cells, or TEXTJOIN(", ", TRUE, A1:A9) for a range with a separator. TEXTJOIN needs Excel 2019 or Microsoft 365.

How do I split a full name into first and last name?

First name: =LEFT(A1, FIND(" ", A1) - 1). Last name: =MID(A1, FIND(" ", A1) + 1, 99). In Microsoft 365 you can use TEXTBEFORE, TEXTAFTER or TEXTSPLIT instead.

How do I count how many times a character appears in a cell?

=LEN(A1) - LEN(SUBSTITUTE(A1, "a", "")). Wrap the text in LOWER first to ignore case, and divide by the target’s length when it has more than one character.

Why does LEFT or MID give me a number I cannot add up?

Text functions always return text. Convert the result with VALUE() or a double minus before adding.

Test yourself

Timed questions on Text Functions, with an explanation for every answer.

Take the Quiz
Upskly AI Team
Learning made simple
Scroll to Top