Avatar of cbridgman
cbridgman
Flag for United States of America asked on

Excel - Remove first line from a multiline cell

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
Microsoft ExcelOffice ProductivityMicrosoft Office

Avatar of undefined
Last Comment
David Pepper

8/22/2022 - Mon
cbridgman

ASKER
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.
ASKER CERTIFIED SOLUTION
Professor J

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
cbridgman

ASKER
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?
Hakan Yılmaz

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

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
STEPHANIE HARRIS

How can I manipulate the formula so that I only keep line one and line 2 and 3 are removed?
Professor J

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))
STEPHANIE HARRIS

I apologize! It's my first time posting. The formula is giving me a #VALUE error.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Professor J

Can you upload the workbook sample because the formula perfectly works based on the example in original post
STEPHANIE HARRIS

Sure, attached here is an example. I only want to keep the first line for every cell. Thank you!
workbook-example.xlsx
Jerry Paladino

Try this formula...  

=IFERROR(LEFT(A2, FIND(CHAR(10),A2)-1), A2)
workbook-example.xlsx
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
David Pepper

bfs