Excel function reference

Text functions

Quick answer

LEFT, RIGHT, MID, LEN, TRIM, SEARCH, and SUBSTITUTE: the everyday toolkit for slicing, inspecting, and cleaning up text.

LEFT(text, num_chars) · RIGHT(text, num_chars) · MID(text, start_num, num_chars) · LEN(text) · TRIM(text) · SEARCH(find_text, within_text, [start_num]) · SUBSTITUTE(text, old_text, new_text, [instance_num])

These seven functions cover almost everything day-to-day spreadsheet work needs from a text value: grabbing the first few characters of a code, pulling a middle segment out of a longer string, measuring length, cleaning up stray spaces from a pasted import, finding where one piece of text sits inside another, and swapping one substring for another.

All seven count character positions starting at 1, not 0, and all seven treat a typed literal exactly the same as text pulled from a cell. SUBSTITUTE is the one most often reached for on messy imported data: a price exported as the text "$0.75" instead of a real number becomes usable with one formula that strips the stray character and converts it back to a number in the same step.

Syntax

LEFT(text, num_chars) · RIGHT(text, num_chars) · MID(text, start_num, num_chars) · LEN(text) · TRIM(text) · SEARCH(find_text, within_text, [start_num]) · SUBSTITUTE(text, old_text, new_text, [instance_num])
ArgumentDescription
LEFT / RIGHTReturn a fixed number of characters from the start or end of a text value.
MIDReturns a substring starting at a given position, for a given length.
LENReturns how many characters are in a text value. No other arguments.
TRIMCollapses extra spaces down to single spaces and trims the ends.
SEARCHReturns the position where one piece of text is found inside another (case-insensitive); no match returns an error.
SUBSTITUTEReplaces every occurrence of old_text with new_text inside text. Add instance_num to replace only the Nth occurrence instead of all of them.

A real example: turning an imported price string back into a number

A data export that stored a dollar amount as text, dollar sign included:

=SUBSTITUTE(A2,"$","")*1

SUBSTITUTE strips the "$" character, leaving behind the text "0.75"; multiplying by 1 is a quick, common way to force that cleaned-up text back into a real number Excel can add up and compare numerically, rather than a VALUE() call, though either works.

Worked examples

LEFT and RIGHT
A
1Code
2US-4471
=LEFT(A2,2) → US
MID for a middle segment
A
1Code
2US-4471-A
=MID(A2,4,4) → 4471
SEARCH for a position
A
1Description
2Laptop Pro 14-inch
=SEARCH("Pro",A2) → 8
SUBSTITUTE to clean up a stray character
A
1Fee (raw)
2$0.75
=SUBSTITUTE(A2,"$","")*1 → 0.75

(the *1 turns the cleaned-up text "0.75" into a real number)

Common mistakes

  • Off-by-one errors in MID's start position. Count characters from 1, including any punctuation.
  • Using RIGHT/LEFT with a fixed length on text that isn't actually a fixed width. Codes that vary in length break this fast.
  • Forgetting SEARCH returns a position, not the found text itself. That trips people expecting VLOOKUP-like behavior.
  • Using SUBSTITUTE to clean up a value and then forgetting it's still text afterward. A formula further downstream that adds or multiplies it needs that *1 (or a wrapping VALUE) first.

Related functions

Try it yourself

A free, graded practice exercise using this exact function: instant feedback, no signup required.

Practice text functions →