To extract part of a cell’s text, use a formula such as TEXTBEFORE for text before a separator, TEXTAFTER for text after one, or MID for characters at set positions. First identify what part you need and what marks its boundaries; then enter the matching formula in an empty cell. The instructions below use Excel for Microsoft 365 on Windows and include alternatives for older Excel versions.
What You’ll Need
- An Excel workbook with the text you want to extract. The examples use a sample value in cell A2; replace A2 with the cell in your sheet.
- A blank cell for the result, usually next to the source data. Leave room to fill the formula down if you have multiple rows.
- A clear idea of the extraction rule: a delimiter such as a hyphen, a fixed character position, or a particular word or symbol.
- Excel for Microsoft 365 or Excel 2024 for TEXTBEFORE, TEXTAFTER, and TEXTSPLIT. If you have an older version, use the compatible LEFT, MID, RIGHT, FIND, and LEN formulas described below.
Step-by-Step
- Inspect the source text and choose the boundary. Click the cell and look at its full contents in the formula bar, not just what is visible in the grid. For example, suppose A2 contains
Order-4821-Blue. The hyphen separates three parts: Order, 4821, and Blue. Decide whether you need the first part, last part, middle part, or a set number of characters. If the text has inconsistent separators, spaces, or missing pieces, note that now because the formula may need an error-handling step. - Choose an empty result cell. Click a blank cell next to the source, such as B2. Keep the original data unchanged while you build and check the formula. Formulas return a result in the cell where you enter them, so the source value remains available for comparison. If you are working with a table, use a column heading such as Extracted Part to make the purpose of the results clear.
- Extract text before a delimiter. If A2 contains
Order-4821-Blueand you want the text before its first hyphen, enter this in B2. This example assumes the source value is in A2 and the delimiter is a hyphen.
=TEXTBEFORE(A2,"-")
The result is Order. TEXTBEFORE returns the characters to the left of the first matching delimiter. Replace the hyphen inside the quotation marks with the separator in your data, such as a comma, slash, or space. TEXTBEFORE is available in Microsoft 365 and Excel 2024; if you do not have it, use the older-version option in the next step.
- Use a compatible formula if TEXTBEFORE is unavailable. With the same layout—source text in A2, with a hyphen separating the part to extract—enter this formula in B2.
=LEFT(A2,FIND("-",A2)-1)
It also returns Order. FIND locates the hyphen, and LEFT returns the characters before it. The minus one excludes the delimiter itself. This formula works in older desktop versions too, but returns an error if A2 has no hyphen; the Troubleshooting section explains how to handle that case.
- Extract text after a delimiter. If A2 contains
Order-4821-Blueand you want everything after the first hyphen, enter the following in B2. The assumed layout is the same: the full text is in A2 and the separator is a hyphen.
=TEXTAFTER(A2,"-")
The result is 4821-Blue, because TEXTAFTER returns everything after the first matching hyphen. To return only the final part after the last hyphen instead, use this version with the same cell and delimiter.
=TEXTAFTER(A2,"-",-1)
That result is Blue. The value -1 tells TEXTAFTER to count the delimiter from the end of the text. TEXTAFTER requires Microsoft 365 or Excel 2024. In older versions, a formula using RIGHT, LEN, and FIND can handle a known delimiter, but extracting after the last of several repeated delimiters takes a more involved formula; consider splitting the text with Text to Columns if you need a one-time result.
- Extract text between two delimiters. For A2 containing
Order-4821-Blue, the middle value is between the first and second hyphens. In B2, use this formula. It assumes the value has two hyphens in that order.
=TEXTBEFORE(TEXTAFTER(A2,"-"),"-")
The formula first gets 4821-Blue, the text after the first hyphen, and then takes the text before the next hyphen. The final result is 4821. Nesting text functions is useful when a value has predictable separators. If some rows have only one hyphen, this formula may return an error for those rows.
- Extract a fixed number of characters. Use MID when you know the character position and length, rather than a separator. With
Order-4821-Bluein A2, the four-digit code begins at character 7. Enter this in B2.
=MID(A2,7,4)
The result is 4821. MID counts spaces and punctuation as characters, so check the positions carefully. If the code can move to a different position from row to row, a delimiter-based formula is usually safer than a fixed-position formula.
- Fill the formula down and check the results. After confirming the first result, select the formula cell and drag its small fill handle in the lower-right corner down alongside your data. Excel adjusts relative references automatically, changing A2 to A3, A4, and so on. Check a few rows with different text patterns before relying on the whole column. If each row follows the same pattern, the extracted values should line up consistently.
- Keep formulas or convert results to fixed values. A formula result updates when its source cell changes. Keep the formula if you want that behavior. If you need a static copy, copy the result cells, then choose Home > Paste > Paste Values. This replaces formulas with their current results, so retain a copy of the formulas if you may need to update the extraction later.
Common Mistakes
Using the wrong delimiter. A hyphen, en dash, underscore, and minus sign can look similar but are different characters. Copy the actual separator from the source text when possible. A formula searching for a regular hyphen will not find an en dash.
Forgetting that spaces count. A leading space is still part of the cell value. It can make an extracted result look blank or create a mismatch in later calculations. If the source has unwanted spaces around the text, clean it first or wrap a suitable extraction formula in TRIM. TRIM removes extra ordinary spaces at the beginning and end, as well as repeated spaces between words; it does not remove every special whitespace character.
Assuming every row has the same structure. A formula that extracts the part between two hyphens works only when both hyphens exist. Before filling down, inspect a few unusual rows, including blanks and values with extra separators.
Overwriting the source or extracting the wrong number of characters. Put the formula in a separate cell, and count punctuation and spaces when using MID. A result that is one character too long may include the delimiter itself.
Expecting a formula result to be a fixed value. The result is linked to the source until you paste values. Conversely, pasting values too early means later changes to the original text will not update the extracted column.
Tips
- Write down the extraction rule in plain language first: “take everything before the first slash” is easier to translate into a formula than guessing at character positions.
- Use TEXTBEFORE and TEXTAFTER when the separator is reliable and the text length varies. Use MID, LEFT, or RIGHT when the character positions or number of characters are consistent.
- For several parts separated by the same character, TEXTSPLIT can spill the parts into neighboring cells. It is available in Microsoft 365 and Excel 2024. Make sure the cells where results will spill are empty, or Excel may show a spill error.
- For a one-time split into separate columns, select the source cells and choose Data > Text to Columns. Follow the wizard, choose Delimited, select the correct separator, and check the preview before finishing. This changes the selected data area, so ensure the destination columns are empty.
- Keep identifiers such as postal codes or account codes as text if leading zeros matter. A value displayed as 0042 may become 42 if treated as a number, which changes the identifier.
- If you use Excel for Mac or Excel for the web, the same formulas generally work when the function is available in that version. Ribbon labels and layout can differ slightly, so use the formula bar and the available Data or Home tab commands if a menu location is not identical.
Troubleshooting
You see #VALUE!. The formula may be looking for a separator that is not in the source cell, or the data may use a visually similar character. Compare the source with the delimiter inside the formula. If some rows legitimately have no delimiter and you want a blank result, use IFERROR. With source text in A2 and a hyphen as the expected separator, enter this in B2.
=IFERROR(LEFT(A2,FIND("-",A2)-1),"")
This returns the text before the hyphen when one exists and a blank when it does not. A blank result can hide unexpected data problems, so check the source rows if you expected every value to contain the delimiter.
You see #NAME?. Your Excel version may not support TEXTBEFORE or TEXTAFTER, or the function name may be misspelled. Use the LEFT and FIND alternative for text before a delimiter, or update Excel if your Microsoft 365 plan includes the newer functions.
The formula appears as text instead of calculating. The cell may be formatted as Text, or the formula may start with an apostrophe. Change the cell format to General, edit the cell, and confirm the formula again. Also check that the first character is an equals sign.
The result includes part of the separator or the wrong section. Review whether the function uses the first or last occurrence and whether your data contains repeated delimiters. For fixed-position MID formulas, recount from the first character, including spaces and punctuation.
You see a spill error after using a splitting formula. One or more cells where Excel needs to place the results are occupied. Clear those cells or move the formula to an area with enough empty columns. Check for hidden content too; a cell can look blank while still containing a space or formula.
Frequently Asked Questions
How do I extract text before a space in Excel?
Use TEXTBEFORE with a space character as its delimiter. For older Excel versions, use LEFT and FIND instead. Check for leading spaces in the source, because they can affect the returned text.
How can I extract the last word from a cell?
If words are separated by ordinary spaces, use TEXTAFTER with a space and an instance number of -1 to return text after the last space. This needs Microsoft 365 or Excel 2024. If spacing is inconsistent, clean the source first and verify cells containing only one word.
Can I extract text between parentheses?
Yes. Use TEXTBETWEEN in Microsoft 365 or Excel 2024 when the opening and closing parentheses reliably surround the desired text. In older versions, combine MID with FIND to locate the opening and closing characters, and test the formula on rows with missing or repeated parentheses.
How do I extract numbers from text?
If the number is in a predictable position or separated by a consistent delimiter, extract it as text first. Convert it to a numeric value only if you need to calculate with it; keep it as text if it is an ID, code, or value with leading zeros.
Will the extracted text update when the original cell changes?
Yes, as long as the result is still a formula linked to the source cell. If you use Paste Values, the formula is replaced with a fixed result and will no longer update automatically.
Can Excel extract text without a formula?
Yes. For a one-off split, use Data > Text to Columns and choose the delimiter. For repeatable, refreshable data cleanup, a formula is usually more convenient because it recalculates when the source changes.
Related
- Excel Day and Month Reversed? Fixing Date Formats
- Excel WEEKDAY: Get the Day of the Week from a Date
- Excel Weekday Name: Show the Day from Any Date in Excel
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Sumifs with date range?Learn how SUMIFS handles dates, boundaries, months, extra criteria, and common errors, with clear Excel examples to help…
- Filter Excel Table by Text: Steps, Options, and FixesTo filter an Excel table by text in Microsoft 365 for Windows, select the drop-down arrow in the…
- DAX SUMIF: How to Sum Values by ConditionDAX has no standalone SUMIF function. To sum a column when a condition is true, create a measure…
- Text Formula Examples in Excel: Clean, Extract, CombineExcel text formulas let you combine words, extract part of a value, standardize capitalization, and clean imported text.…
- SUMIF Excel Examples With Two Criteria to Match RowsTo total values that match two conditions in Excel, use SUMIFS rather than SUMIF. With regions in A2:A8,…
- Round Down in Excel: Formulas for Specific Decimal PlacesTo round a value down to a chosen number of decimal places in Excel, use the ROUNDDOWN function.…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.