How to extract first line in Excel cell
In this tutorial, you will learn 3 effective approaches to extracting the first line of text from Excel cells: formulas, regex.
In data analysis, Excel is a powerful tool that helps make difficult tasks easier. One useful task is pulling out specific content from a cell. This can help you organize and present data more clearly. In this article, we’ll explore different ways to extract the first line from a cell that has multiple lines of text.
Table of Contents
How to extract the first line in Excel cell with formula
- Find where the line breaks
Excel uses a special character to show a new line. You can use CHAR(10) in a formula to find it. - Get the position of the line break
Use the FIND or SEARCH function to figure out where the first line break happens in the cell:
FIND(CHAR(10), cell) or SEARCH(CHAR(10), cell) - Adjust the position
Excel starts counting from 1 (not 0 like some programming languages), so to get only the text before the line break, subtract 1:
FIND(CHAR(10), cell) – 1 - Pull out the first line
Now that you know where the first line ends, use the LEFT function to grab just that part of the text.
Here’s the basic formula:
LEFT(cell, FIND(CHAR(10), cell) – 1)
If your text is in cell A3, the formula would look like this:
=LEFT(A3, FIND(CHAR(10), A3) – 1)
This formula works really well when the cell has multiple lines. It pulls out just the first line.
But there’s one small problem:
If the cell has only one line, there’s no line break for Excel to find. So the FIND function won’t work, and the formula gives an error: #VALUE!
The solution:
You can fix this by using the IFERROR function. It tells Excel:
“If there’s an error, just show the full cell instead.”
Here’s the improved version:
=IFERROR(LEFT(A3, FIND(CHAR(10), A3) – 1), A3)

By learning these nuances, you can confidently use formulas to grab the first line from Excel cells, no matter the situation.
Get the first line of text in Excel 365
In Excel 365, there’s an even easier way to grab the first line of text from a cell—use the TEXTBEFORE function. This function pulls everything that comes before a character you choose. Since line breaks are marked by CHAR(10), you can use:
If your text is in A3, the formula is:
That works fine when there is a line break. But if the cell has only one line, TEXTBEFORE can return an error. To stop that, wrap it in IFERROR. This tells Excel, “If there’s a problem, just show the full text instead”:
This formula-driven technique guarantees a reliable method for extracting the first line of text from Excel 365 cells, irrespective of whether they contain multiple lines or just one line.

Keep only the first line of text using VBA Code
Another way to get just the first line from a cell and ignore the rest is by using regular expressions (also called regex). This uses a special custom VBA function called RegExpExtract with this pattern:
RegExpExtract(text, pattern, [instance_num], [match_case])
What it does: it looks for everything before the first new line character (\n) in your cell and pulls out that part.
You can use this formula:
RegExpExtract(cell, “.*\n”, 1)
Let’s explain the parts:
- cell — the cell that has multiple lines of text.
- “.*\n” — this pattern (regex) means: “any characters followed by a new line.”
- 1 — means “grab the first match.”
Example:
To copy the first line from cell A3 into cell B3, use:
=RegExpExtract(A3, “.*\n”, 1)
One thing to know:
If the cell has only one line (no new line), this formula will give you a blank because it can’t find a line break.
How to fix this:
Use an IF formula to check if the result is empty. If it is, just show the full text instead. If not, show the first line:
This way, column B will always show something — either the first line (if there are many) or the full text (if there is only one line).

Here is the VBA code that is used to extract data using ‘VBScript.RegExp’
Public Function RegExpExtract(strText As String, strPattern As String, Optional iInstance As Integer = 0, Optional bMatchCase As Boolean = True)
Dim regex As Object
Dim matches As Object
Dim str_matches() As String
Dim lMatchIndex As Long
On Error GoTo Error1
RegExpExtract = ""
Set regex = CreateObject("VBScript.RegExp")
regex.pattern = strPattern
regex.Global = True
regex.MultiLine = True
If True = bMatchCase Then
regex.ignorecase = False
Else
regex.ignorecase = True
End If
Set matches = regex.Execute(strText)
If 0 < matches.Count Then
If (0 = iInstance) Then
ReDim str_matches(matches.Count - 1, 0)
For lMatchIndex = 0 To matches.Count - 1
str_matches(lMatchIndex, 0) = matches.Item(lMatchIndex)
Next lMatchIndex
RegExpExtract = str_matches
Else
RegExpExtract = matches.Item(iInstance - 1)
End If
End If
Exit Function
Error1:
RegExpExtract = CVErr(xlErrValue)
End Function
Throughout this guide, we’ve sliced, diced, and compared these three tactics, dishing out some handy tips along the way. I hope you enjoyed this tutorial and can now dive into your next data adventure armed with new knowledge 😊






