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.