Note: The other languages of the website are Google-translated. Back to English

Extract last line of text from a multi-line cell

To extract the last line of text from a text string which is separated by line breaks, normally, there is no direct way for you to solve this. This article, I will introduce a formula to deal with this task in Excel.

Extract the last line of text from a multi-line cell in Excel

In Excel, you can create a formula based on the TRIM, RIGHT, SUBSTITUTE and REPT functions to extract the last line from a multi-line cell. The generic syntax is:

=TRIM(RIGHT(SUBSTITUTE(text,CHAR(10),REPT(" ",200)),200))
  • text: the text string or cell value that you want to extract last line from.
  • 200: the number 200 is a random number which should be big enough to handle the long lines, you can adjust it to bigger if your lines are longer.

1. Please enter or copy the below formula into a blank cell:


2. Then, drag the fill handle down to the cells that you want to apply this formula, and all the last line texts in each cell have been extracted as below screenshot shown:

Explanation of the formula:
  • SUBSTITUTE(A2,CHAR(10),REPT(" ",200): This SUBSTITUTE function is used to find all line breaks (char10) in cell A2 and replace each one with 200 space characters.
  • RIGHT(SUBSTITUTE(A2,CHAR(10),REPT(" ",200)),200): The RIGHT function is used to extract 200 characters from the right side of the new text returned by the SUBSTITUTE function.
  • TRIM(): This TRIM function removes all leading spaces from the text returned by the RIGHT function.

Relative functions used:

  • REPT:
  • The REPT function is used to repeat the characters a specified number of times.
  • The SUBSTITUTE function replaces text or characters within a text string with another text or characters.
  • RIGHT:
  • The RIGHT function returns the text from right of the text string.
  • TRIM:
  • The TRIM function removes all extra spaces from text string and only keeps single spaces between words.

More articles:

  • Extract Substring From Text String In Excel
  • It may be a common task for you that you need to extract substrings from text strings, in Excel, there is not a direct function for doing this, but, with the help of the LEFT, RIGHT, MID and SEARCH functions, you can extract kinds of substrings as you need.

The Best Office Productivity Tools

Kutools for Excel - Helps You To Stand Out From Crowd

Would you like to complete your daily work quickly and perfectly? Kutools for Excel brings 300 powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) and save 80% time for you.

  • Designed for 1500 work scenarios, helps you solve 80% Excel problems.
  • Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands.
  • Become an Excel expert in 3 minutes. No longer need to remember any painful formulas and VBA codes.
  • 30-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years.
Ribbon of Excel (with Kutools for Excel installed)

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, Firefox, And New Internet Explorer.
Screen Shot of Excel (with Office Tab installed)
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet

Follow Us

Copyright © 2009 - | All rights reserved. Powered by ExtendOffice. | Sitemap
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.
Protected by Sectigo SSL