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 in Excel
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.
Relative functions used:
- The Excel TRIM function removes all extra spaces from text string and only keeps single spaces between words.
- Return the specific characters from the middle of text string.
- The Excel SUBSTITUTE function replaces text or characters within a text string with another text or characters.
- The REPT function is used to repeat the characters a specified number of times.
- The LEN function returns the number of characters in a text string.
- 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.