fxExcelReps

← How-to guides

How to Split Text by a Delimiter in Excel

To split BG-1024-SOF at the dashes, take the part before the first dash, between the dashes and after the last one. In Microsoft 365, TEXTBEFORE and TEXTAFTER do it in one step each; in older versions combine LEFT, MID and FIND. Without formulas, use Data → Text to Columns.

{"cells": {"A1": "Code", "A2": "BG-1024-SOF", "A3": "RO-512-BUC", "A4": "UK-7-LON", "B1": "Country", "B2": "=TEXTBEFORE(A2,\"-\")", "B3": "=TEXTBEFORE(A3,\"-\")", "B4": "=TEXTBEFORE(A4,\"-\")", "C1": "Number", "C2": "=TEXTBEFORE(TEXTAFTER(A2,\"-\"),\"-\")", "C3": "=TEXTBEFORE(TEXTAFTER(A3,\"-\"),\"-\")", "C4": "=TEXTBEFORE(TEXTAFTER(A4,\"-\"),\"-\")", "D1": "City", "D2": "=TEXTAFTER(A2,\"-\",-1)", "D3": "=TEXTAFTER(A3,\"-\",-1)", "D4": "=TEXTAFTER(A4,\"-\",-1)"}, "focus": "C2", "note": "Type a new code in A2, like DE-3300-BER."}

TEXTBEFORE and TEXTAFTER (Microsoft 365)

Before the first separator, after the last one (-1), and the middle part by combining both.

=TEXTBEFORE(A2, "-")BG.
=TEXTBEFORE(TEXTAFTER(A2, "-"), "-")1024.
=TEXTAFTER(A2, "-", -1)SOF.

LEFT, MID and FIND (every version)

FIND gives the position of each dash; LEFT and MID cut around it.

=LEFT(A2, FIND("-", A2)-1)Before the first dash.
=MID(A2, FIND("-", A2)+1, FIND("-", A2, FIND("-", A2)+1)-FIND("-", A2)-1)Between the two dashes.

Text to Columns (no formulas)

Select the column, Data → Text to Columns → Delimited, tick the separator, Finish. It overwrites the cells to the right, so leave them empty.

Data → Text to ColumnsSplits once; doesn't update when the data changes.

Common mistakes

The numbers come back as text
Text functions always return text. Put -- in front to get a number: =--TEXTBEFORE(TEXTAFTER(A2, "-"), "-").
#VALUE! or #N/A
A row doesn't contain the separator. Wrap the formula in IFERROR.

Frequently asked questions

How do I split into many columns at once?

In Microsoft 365, =TEXTSPLIT(A2, "-") spills every part into its own column.

How do I split by a line break?

Use CHAR(10) as the separator: =TEXTBEFORE(A2, CHAR(10)).

Can I split names this way?

Yes, with a space as the separator. See extract the first name.

Practise it

TEXTBEFORE, TEXTAFTERMIDFINDLEFT

Think you know this?

15 formula tasks, no hints, with a leaderboard. Absolute, relative and mixed references included.

Take the Pro Challenge →

More how-to guides

How to Sum by Month in Excel

Total amounts by month in Excel from a list of dates, with SUMIFS and EOMONTH or SUMPRODUCT with MONTH. Live example included.

How to Calculate Age in Excel

Calculate age from a date of birth in Excel with DATEDIF, in years or in years and months, and why subtracting years gives wrong ages.

How to Calculate Days Between Two Dates in Excel

Count days between two dates in Excel by subtracting them, count working days with NETWORKDAYS, and get months or years with DATEDIF.

How to Get the Last Day of the Month in Excel

Get the last day of a month in Excel with EOMONTH, plus the first day of the month, the number of days and the last working day.