How to Extract a Line Beginning with a Specific Word from an Excel Cell
Question details
The user needs to clean Excel cells containing multiple lines of text by extracting only the specific line that begins with a certain target word.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Cleaning messy data where hundreds of rows contain unwanted text around one required line, necessitating a formula to isolate the target string.
- Observed behavior
- The cell contains multiple lines separated by line breaks, and the user needs to return exclusively the line starting with a specified word.
Identify the exact target word you are looking for and count its number of characters, as this will be required for the text extraction formula.
Use LET, TEXTSPLIT, and XLOOKUP in Microsoft 365
This modern formula quickly separates lines within a cell and returns the line that begins with your specific target word.
This approach leverages newer dynamic array formulas available in Microsoft 365. TEXTSPLIT breaks the multi-line cell into an array based on line breaks, while LEFT and XLOOKUP pinpoint the exact matching text.
Click on an empty cell in the row where you want the extracted line of text to appear.
Type the formula =LET(lines,TRIM(TEXTSPLIT(A1,,CHAR(10))),XLOOKUP(TRUE,LEFT(lines,4)="mesh",lines,"")) into the formula bar. Replace 'A1' with your source cell, 'mesh' with your specific word, and '4' with the character length of your specific word.
Press Enter to extract the text. Click the cell with your newly extracted line, then drag the fill handle from the bottom-right corner downward to apply this logic to the remaining rows.

Extract Using Power Query (For Older Excel Versions)
If you are using an older version of Excel, Power Query provides a robust, formula-free way to split data by delimiters and filter for the exact text you need.
Extract Multi-line Cell Data Effortlessly with WPS Spreadsheet
WPS Spreadsheet provides powerful data processing tools, including advanced text formulas and robust text-to-columns functionality, helping you clean and organize messy data in seconds without complex setups.
- 1. Open your dataset in WPS Spreadsheet: Launch WPS Office and open your workbook containing the multi-line cells that need cleaning.
- 2. Input the text extraction formula: Select a blank cell adjacent to your data and input your text manipulation formulas, or utilize the 'Text to Columns' tool located under the Data tab to split text by delimiters.
- 3. Process the entire column instantly: Double-click the fill handle in the bottom-right corner of your selected cell to instantly extract the target text lines for the rest of your dataset.

Frequently Asked Questions
What does CHAR(10) do in the text extraction formula?
CHAR(10) represents a line break (or line feed) character in Excel. In the formula, it tells the TEXTSPLIT function exactly where the cell's internal lines are separated so it can break the text block into individual segments.
Why am I getting a #NAME? error when using TEXTSPLIT?
The #NAME? error typically occurs if you are using a version of Excel that does not support the TEXTSPLIT or LET functions (such as Excel 2016 or 2019). You will need to use a helper-column approach, Power Query, or upgrade your software.
How can I extract a line containing a specific word, rather than just beginning with it?
Instead of using the LEFT function, you can use the SEARCH function combined with ISNUMBER. Modify the XLOOKUP criteria to look for a line where SEARCH returns a number, which means the word exists anywhere within that specific line.




