How to extract text from a cell in Excel
To extract text from a cell, use LEFT for the first characters, RIGHT for the last characters and MID for the middle. Each takes the text and a number of characters. When the part you want sits next to a character such as a dash or a space, TEXTAFTER and TEXTBEFORE find it for you.
The examples below take apart an invoice code. Practice the same moves in the text lessons at the end.
1. The first characters with LEFT
=LEFT(text, count) returns that many characters from the start. If you leave out the count, you get one character. RIGHT works the same way from the end of the text.
Example: The prefix of a code
| A | B | |
|---|---|---|
| 1 | Code | Prefix |
| 2 | INV-2024-0183 | INV |
The first three characters of INV-2024-0183 are INV.
2. The middle with MID
=MID(text, start, count) returns characters from any position. The first character is position 1. Count the dash too: in INV-2024-0183 the year starts at position 5, because I, N, V and the dash take positions 1 to 4.
Example: The year in the middle
| A | B | |
|---|---|---|
| 1 | Code | Year |
| 2 | INV-2024-0183 | 2024 |
Starting at position 5, four characters give 2024. The result is text, so use VALUE to turn it into a number.
3. Text after a delimiter with TEXTAFTER
When the parts differ in length, counting characters stops working. TEXTAFTER returns what comes after a delimiter, and an optional third argument picks which occurrence to use. It is available in Microsoft 365 and Excel 2024. In older versions, combine FIND with LEFT, MID and LEN to locate the delimiter.
Example: The number after the second dash
| A | B | |
|---|---|---|
| 1 | Code | Number |
| 2 | INV-2024-0183 | 0183 |
The 2 means after the second dash, which leaves 0183 with its leading zero.
4. Text between two characters
To take what sits between two delimiters, nest the functions: TEXTBEFORE(TEXTAFTER(A2,"-"),"-") returns 2024, the text after the first dash and before the next one. Without TEXTAFTER, use MID with FIND to calculate the start and the length.
5. Turn the result into a number
LEFT, MID, RIGHT and TEXTAFTER always return text, even when the characters are digits. A leading zero survives as text, which is often what you want for codes. When you need to calculate, wrap the formula in VALUE or multiply it by 1.
Common mistakes
Counting the start position from 0. The first character is position 1.
Fix: Count the dash and every other character, starting from 1.
Fixed counts on text of varying length. LEFT(A2,3) breaks as soon as a name has four letters.
Fix: Find the delimiter with FIND, or use TEXTBEFORE and TEXTAFTER.
Extracted numbers that will not add up. They are text, and SUM ignores text.
Fix: Wrap the extraction in VALUE, or multiply it by 1.
Frequently asked questions
How do I extract the first word of a cell?
Use =TEXTBEFORE(A2," "), or in older versions =LEFT(A2,FIND(" ",A2)-1). See the guide on splitting text for more.
How do I extract the last word?
=TEXTAFTER(A2," ",-1) returns the text after the last space in Microsoft 365.
Can I extract without formulas?
Yes. Text to Columns and Flash Fill do it with buttons, but they do not update when the source changes.
Related functions
- LEFTLEFT returns the first characters of a text, RIGHT the last ones.
- MIDMID returns characters from the middle of a text: a start position and a length.
- TEXTAFTERTEXTAFTER and TEXTBEFORE split text at a delimiter, such as the @ in an e-mail, without counting positions.
- FINDFIND and SEARCH return the position of one text inside another.
- LENLEN returns the number of characters in a text, spaces included.
More on extracting text
The guide covers LEFT, MID and TEXTAFTER on one invoice code. This piece adds how to find the position of a character, how to extract text of varying length with FIND, and how to split a code into separate columns with one formula per part.
Find the position first
When the parts differ in length, the positions must be calculated. FIND returns the position of one text inside another, so the position of a dash tells you where to cut. FIND is case sensitive and returns #VALUE! when the text is missing, while SEARCH ignores case and allows wildcards.
=FIND("-",A2)
=LEFT(A2,FIND("-",A2)-1)Text of varying length
To take the part after the first dash, combine MID with FIND and LEN. Start one character after the dash and ask for more characters than can remain, because MID stops at the end of the text. A big number such as 100 is a common trick for this.
=MID(A2,FIND("-",A2)+1,100)
=RIGHT(A2,LEN(A2)-FIND("-",A2))One formula per part
To split INV-2024-0183 into three columns, give each part its own formula: the prefix with LEFT, the year with MID and the number with RIGHT. Because the parts here always have the same length, fixed counts are fine, and they are easier to read than the dash-finding version. Check a few rows from the bottom of the data too, because the longest and the shortest codes are where a fixed count breaks.
If the result must be a number, convert it. For the full range of tools, read [how to split text](/guides/split-text-in-excel) and practice in [the text extraction lesson](/learn/text-extract) and [the extract words lesson](/learn/extract-words).