How to Substring in Excel: Step-by-Step Guide
In this article
To extract part of a text string in Excel, use the functions LEFT, RIGHT, MID, TEXTBEFORE, TEXTAFTER, or TEXTSPLIT. The most common is MID, which pulls a set number of characters starting at a position you choose. For example, =MID(A1,4,5) returns five characters from cell A1 beginning with the fourth character. This guide shows exact steps for each function, plus fixes for the usual errors.
What You'll Need
- Excel 2013 or later for LEFT, RIGHT, MID, FIND, and SEARCH. TEXTBEFORE, TEXTAFTER, and TEXTSPLIT require Microsoft 365 or Excel 2021 and later; they are not in older perpetual versions.
- A worksheet with text in a cell (for example, names, codes, or addresses).
- Basic familiarity with cell references and the formula bar.
Menu labels and function availability can differ slightly by Excel version and platform. The steps below work in Excel for Windows and Mac; Excel for the web supports the same core functions.
Step-by-Step
- Decide what you want to extract. Write down the starting position and how many characters you need. For a product code like
AB-1234-XY, the middle number starts at character 4 and is 4 characters long. - Click the cell where the result should appear. This is usually an empty column next to your data.
- Type the formula for your case. Use one of these:
=LEFT(A1,3)returns the first 3 characters.=RIGHT(A1,2)returns the last 2 characters.=MID(A1,4,4)returns 4 characters starting at position 4.
- Press Enter. The extracted text appears in the cell. If you see a
#VALUE!error, check that the start number and length are positive numbers. - Copy the formula down. Drag the fill handle (the small square at the bottom-right of the cell) down the column. Relative references adjust automatically.
- For text between delimiters, use FIND or SEARCH inside MID. For example, to get the text between two hyphens in
AB-1234-XY:=MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1). FIND is case-sensitive; SEARCH is not. - If you have Microsoft 365 or Excel 2021+, try TEXTBEFORE and TEXTAFTER.
=TEXTBEFORE(A1,"-")returnsAB;=TEXTAFTER(A1,"-")returns1234-XY. Add the optional instance number to get later occurrences:=TEXTAFTER(A1,"-",2)returnsXY. - Use TEXTSPLIT to break a string into multiple cells.
=TEXTSPLIT(A1,"-")spills the parts across adjacent cells. This is available only in Microsoft 365 and Excel 2021 and later. - Convert formulas to values if needed. Select the results, press Ctrl+C (Cmd+C on Mac), then right-click and choose Paste Special > Values. This removes the formulas so the text stays fixed if the source data changes.
Common Mistakes
- Counting from zero. Excel's MID counts the first character as position 1, not 0. Starting at 0 returns
#VALUE!. - Using FIND with text that is not there. If the delimiter is missing, FIND returns
#VALUE!. Wrap it in IFERROR to show a blank or a message. - Forgetting that LEFT and RIGHT count spaces. A leading or trailing space is a character. Use TRIM first if your data has extra spaces.
- Assuming TEXTBEFORE works in older Excel. It does not; you will get
#NAME?. Use LEFT, RIGHT, MID, FIND, or SEARCH instead. - Hard-coding positions that vary. If the start position changes between rows, calculate it with FIND or SEARCH rather than typing a fixed number.
Tips
- Use SEARCH instead of FIND when the delimiter might be uppercase or lowercase; SEARCH ignores case.
- Wrap formulas in IFERROR to keep the sheet clean:
=IFERROR(MID(A1,4,4),""). - Test on a copy of your data first. Substring formulas do not change the original cell, but Paste Special > Values will overwrite if you paste over the source.
- For very long strings, use LEN to check total length before choosing a start position:
=LEN(A1). - If you need to extract text between parentheses or other paired characters, FIND both the opening and closing character and subtract the positions.
Troubleshooting
- #VALUE! error: The start number or length is not a positive number, or FIND did not locate the delimiter. Check each argument with a separate formula.
- #NAME? error: The function name is misspelled, or you are using TEXTBEFORE, TEXTAFTER, or TEXTSPLIT in a version that does not support them. Switch to LEFT, RIGHT, MID, FIND, or SEARCH.
- Result is blank or wrong: Confirm the cell reference points to the text you expect. Use F2 to edit the formula and check the highlighted references.
- Formula returns a number instead of text: Some results look numeric but are stored as text. Use VALUE to convert if you need to calculate with them.
- Drag-fill changes the wrong references: Use absolute references with $ (for example,
$A$1) for fixed positions or delimiters that should not move.
If none of these fix it, copy the formula into a new blank cell and test with a short, simple string. That isolates whether the problem is the formula or the source data.
Frequently Asked Questions
What is the difference between LEFT, RIGHT, and MID?
LEFT returns characters from the start, RIGHT from the end, and MID from any position you specify. All three take a cell reference and a character count; MID also takes a start position.
Can I extract text after a specific character?
Yes. In Microsoft 365 or Excel 2021 and later, use TEXTAFTER. In older versions, combine MID with FIND or SEARCH to locate the character and return everything after it.
Why does my substring formula return #VALUE!?
The most common causes are a start position of 0, a negative length, or a FIND that cannot locate the delimiter. Check that all numeric arguments are positive and that the delimiter exists in the text.
Does substring work in Excel for the web?
Yes, LEFT, RIGHT, MID, FIND, and SEARCH work in Excel for the web. TEXTBEFORE, TEXTAFTER, and TEXTSPLIT are available in Microsoft 365 versions, including the web app, but not in older perpetual versions.
How do I extract text between two characters?
Use MID with two FIND functions: one for the opening character and one for the closing character. The start position is the first FIND plus 1, and the length is the difference between the two positions minus 1.
Can I substring numbers as well as text?
Yes. LEFT, RIGHT, and MID treat numbers as text and return text. If you need a numeric result, wrap the formula in VALUE, for example =VALUE(MID(A1,4,4)).