Skip to main content

Extract multiple lines from a cell

Author: Xiaoyang Last Modified: 2020-09-11

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

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:

=TRIM( MID(SUBSTITUTE( $A2, CHAR(10), REPT( " ",LEN($A2) ) ), (C$1-1)*LEN($A2)+1, LEN($A2)) )

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!

doc kte extract multi lines


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.

The Best Office Productivity Tools

Kutools for Excel - Helps You To Stand Out From Crowd

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates  |  Delete Blank Rows  |  Combine Columns or Cells without Losing Data  |  Round without Formula ...
Super VLookup: Multiple Criteria  |  Multiple Value  |  Across Multi-Sheets  |  Fuzzy Lookup...
Adv. Drop-down List: Easy Drop Down List  |  Dependent Drop Down List  |  Multi-select Drop Down List...
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus  |  Design View  |  Big Formula Bar  |  Workbook & Sheet Manager | Resource Library (Auto Text)  |  Date Picker  |  Combine Worksheets  |  Encrypt/Decrypt Cells  |  Send Emails by List  |  Super Filter  |  Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters ...)  |  50+ Chart Types (Gantt Chart ...)  |  40+ Practical Formulas (Calculate age based on birthday ...)  |  19 Insertion Tools (Insert QR Code, Insert Picture from Path ...)  |  12 Conversion Tools (Numbers to Words, Currency Conversion ...)  |  7 Merge & Split Tools (Advanced Combine Rows, Split Excel Cells ...)  |  ... and more

Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need is Just A Click Away...

Description


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.
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations