Text Formulas

How to Extract Text From a Cell in Excel

Pull out the first, last or middle characters of any cell with LEFT, RIGHT and MID, and find the text before or after a space, dash or comma.

On this page
  1. Use LEFT, RIGHT or MID when the position is fixed
  2. Find the position first
  3. Get the last word
  4. Handle cells without the separator
  5. Fix results that look wrong
  6. Try Flash Fill for a one-off job

Use LEFT, RIGHT or MID when the position is fixed

If the part you want always sits in the same place, three text functions do the job directly:

  • =LEFT(A2,3) returns the first 3 characters.
  • =RIGHT(A2,4) returns the last 4 characters.
  • =MID(A2,5,3) returns 3 characters, starting at position 5.

LEFT and RIGHT take one character if you leave out the number. MID always needs a start position and a count.

Say A2 holds ABC-1234. LEFT returns ABC, RIGHT returns 1234, and MID(A2,5,3) returns 123.

Find the position first

When the piece you need moves around, use FIND to locate the separator, then cut the text on either side of it.

  • Text before the first space: =LEFT(A2,FIND(" ",A2)-1). For “Jane Smith” this returns “Jane”.
  • Text after the first space: =MID(A2,FIND(" ",A2)+1,LEN(A2)). For “Jane Smith” this returns “Smith”. Using LEN for the count is safe because MID stops at the end of the text.
  • Text between two dashes: =MID(A2,FIND("-",A2)+1,FIND("-",A2,FIND("-",A2)+1)-FIND("-",A2)-1). For “AB-123-XY” this returns “123”.

The last formula works in two steps. The first FIND finds the first dash. The second FIND starts looking just after it, to find the next dash. The difference between the two positions, minus one, is the number of characters to take.

Get the last word

Excel has no simple function for the text after the last space in older versions. In Microsoft 365, TEXTAFTER does it with a -1 instance, as in =TEXTAFTER(A2," ",-1). It returns an error if there’s no space. This formula works in any version:

=TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),100))

It replaces every space with 100 spaces, takes the last 100 characters, which hold only the last word, and then trims the extra spaces. The word itself has to be shorter than 100 characters.

Handle cells without the separator

FIND returns an error when the separator isn’t in the cell, and the whole formula shows that error. Wrap it in IFERROR to return the original text instead:

=IFERROR(LEFT(A2,FIND(" ",A2)-1),A2)

This is a sensible default for a single word, but check whether a blank result would suit your data better. When IFERROR helps and when it hides a real problem is covered in how to hide errors in excel formulas.

Fix results that look wrong

  • Extra spaces at the start or end of a value change the result. Wrap the whole formula in TRIM, as in =TRIM(MID(...)). The cleanup steps are in remove extra spaces in excel formula.
  • Extracted numbers come back as text, because LEFT, RIGHT and MID always return text. If you need to add them, convert them first with VALUE or --, as explained in how to convert text to number in excel.
  • Check what a cell holds with =LEN(A2), which counts every character, spaces included.

Try Flash Fill for a one-off job

If the text follows a clear pattern and you only need the result once, type the answer for the first row, select the cells below it, and press Ctrl+E. Flash Fill copies the pattern. It doesn’t update when the source changes, so a formula is the safer choice for a list that grows.

The complete guide to text formulas

Text Formulas in Excel Explained
Read the guide

Keep exploring

Guides from other topics

All topics →