Extract multiple lines from a cell
If you have a list of text strings which are separated by line breaks (that occurs by pressing Alt + Enter keys when entering the text), and now, you want to extract these lines of text into multiple cells as below screenshot shown. How could you solve it with a formula in Excel?
- Extract multiple lines from a cell with formula
- Extract multiple lines from a cell with a handy utility
Extract multiple lines from a cell with formula
To extract each line from a multiple-line cell into separate cells, you can use the combination of the TRIM, MID, SUBSTITUTE, REPT, and LEN functions. Please do with the following steps:
1. First, you should enter a list of numbers that you want to extract the line text into a row, for instance, enter 1 to 4 into the range C1:F1, see screenshot:
2. Then, enter or copy the below formula into the cell C2:
3. Then, drag the fill handle to right cells to get all the text into separate cells, see screenshot:
4. Keep on dragging the fill handle down to the range of cells that you want to apply this formula, and all lines of text have been extracted as following screenshot shown:
Explanation of the formula:
- SUBSTITUTE( $A2, CHAR(10), REPT( " ",LEN($A2) ) ): this SUBSTITUTE function is used to replace all line breaks with a new text string returned by the REPT function. This returned string will be used as the text argument within the MID function.
- (C$1-1)*LEN($A2)+1: this part is used to return the starting position of the first, second or nth substring. The returned value will be used as the start_num argument within the MID function.
- LEN($A2): this LEN function returns the total length of the text string in cell A2. The returned value will be used as the num_chars argument within the MID function.
- So the formula will be recognized as this:
- TRIM(): the TRIM function removes all extra spaces from text string between words.
Extract multiple lines from a cell with a handy utility
If you are painful with the complex formulas, Kutools for Excel supports an easy feature - Split Cells, with this useful tool, you can split the cell contents into multiple rows or columns based on any specific separator you need. Click to download Kutools for Excel for free trial!
Relative functions used:
- TRIM:
- The Excel TRIM function removes all extra spaces from text string and only keeps single spaces between words.
- MID:
- Return the specific characters from the middle of text string.
- SUBSTITUTE:
- The Excel SUBSTITUTE function replaces text or characters within a text string with another text or characters.
- REPT:
- The REPT function is used to repeat the characters a specified number of times.
- LEN:
- The LEN function returns the number of characters in a text string.
More articles:
- Check If Cell Equals Any Value In List
- For example, I have a list of text strings in column A, and now, I want to check if cell value in this column equals any value in another list of column E. If equals, display TRUE, otherwise, a FALSE value is displayed as below screenshot shown.
- Count Keywords Cell Contains Based On A List
- If you want to count the number of keywords appears in a cell based on a list of cells, the combination of the SUMPRODUCT, ISNUMBER and SEARCH functions may help you to solve this problem in Excel.
- Count Lines Which Are Separated By Line Breaks In A Cell Or A Range
- This article is talking shout how to count the number of lines which are separated by line breaks in a cell or a range of cell by using formula in Excel.
The Best Office Productivity Tools
Kutools for Excel - Helps You To Stand Out From Crowd
Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need is Just A Click Away...
Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)
- One second to switch between dozens of open documents!
- Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
- Increases your productivity by 50% when viewing and editing multiple documents.
- Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Edge and Firefox.