Solved

Excel - Remove first line from a multiline cell

Posted on 2014-11-22
11
5,313 Views
Last Modified: 2016-09-22
I have an Excel spreadsheet with a column in it that contains multiple lines in each cell. The lines in those cells are separated by a line break (when entering data in the cell, pressed Alt + Enter to start new lines). I want to remove the first line in every one of those cells and leave the rest of the lines.

Can you help?

Cell contents appear as follows:

This is line 1
This is line 2
This is line 3

I want the result to look as follows:

This is line 2
This is line 3
0
Comment
Question by:cbridgman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
11 Comments
 

Author Comment

by:cbridgman
ID: 40459662
I would like to do this with a formula rather than a macro. I'll take a macro if I have to but I really don't know how to set those up.
0
 
LVL 26

Accepted Solution

by:
ProfessorJimJam earned 250 total points
ID: 40459780
=RIGHT(a2,LEN(a2)-FIND(CHAR(10),a2,1))  assuming your data is a2
0
 

Author Comment

by:cbridgman
ID: 40460259
That almost does the trick but the line breaks disappear as follows:

Original Cell Content

This is line 1
This is line 2
This is line 3

Cell Content After Applying Formula

This is line 2This is line 3

Any way to prevent the removal of line breaks?
0
Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

 
LVL 5

Expert Comment

by:Hakan Yılmaz
ID: 40460324
You may try this.
Option Explicit

Sub RemoveFirstLine(ByRef SearchRange As Range)
    Dim iterCell As Range
    For Each iterCell In SearchRange.Cells
        iterCell.Value = Right(iterCell.Value, Len(iterCell.Value) - InStr(1, iterCell.Value, Chr(10)))
    Next iterCell
End Sub

Open in new window


You should call this sub with a reference to the range object which has strings to be manipulated.

Example:
Sub StartRemove()
    RemoveFirstLine ActiveWorkbook.ActiveSheet.UsedRange
    RemoveFirstLine ActiveWorkbook.ActiveSheet.Range("B4:B5")
    RemoveFirstLine ThisWorkbook.Worksheets("Sheet1").Range("B4:B5")
End Sub

Open in new window

0
 
LVL 16

Assisted Solution

by:Jerry Paladino
Jerry Paladino earned 250 total points
ID: 40460558
The formula   =MID(A2,FIND(CHAR(10),A2),999)   will remove the first line.  

Note in your file where the cells have the three line text,  "Wrap Text" is enabled by default.  You will need to set the cells where you use this formula to Wrap Text for it to display correctly.
HTH,
JerryQ_28567654_ScreenshotQ-28567654.xlsx
0
 

Expert Comment

by:STEPHANIE HARRIS
ID: 41811070
How can I manipulate the formula so that I only keep line one and line 2 and 3 are removed?
0
 
LVL 26

Expert Comment

by:ProfessorJimJam
ID: 41811089
Stephanie.

it would have better if you opened a question for this. rather than adding the question on someone else question.  anyways,  you can get what you need by this formula

=LEFT(LEFT(A2,LEN(A2)-FIND(CHAR(10),A2,1)),LEN(LEFT(A2,LEN(A2)-FIND(CHAR(10),A2,1)))-FIND(CHAR(10),LEFT(A2,LEN(A2)-FIND(CHAR(10),A2,1)),1))
0
 

Expert Comment

by:STEPHANIE HARRIS
ID: 41811097
I apologize! It's my first time posting. The formula is giving me a #VALUE error.
0
 
LVL 26

Expert Comment

by:ProfessorJimJam
ID: 41811107
Can you upload the workbook sample because the formula perfectly works based on the example in original post
0
 

Expert Comment

by:STEPHANIE HARRIS
ID: 41811111
Sure, attached here is an example. I only want to keep the first line for every cell. Thank you!
workbook-example.xlsx
0
 
LVL 16

Expert Comment

by:Jerry Paladino
ID: 41811669
Try this formula...  

=IFERROR(LEFT(A2, FIND(CHAR(10),A2)-1), A2)
workbook-example.xlsx
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
Gain an elementary understanding of Blockchain technology.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question