The part of the code before the dash. The prefixes have different lengths.
AB
1Code
2GHIJ-4821

In B2, write =LEFT(A2,FIND("-",A2)-1) and it shows GHIJ.

Cutting text apart

LEFT(text, n) and RIGHT(text, n) take n characters from either end. MID(text, start, n) takes n characters from a position, where 1 is the first character. LEN gives the length.

When the pieces vary in length, find the cut with FIND: the prefix before a dash is LEFT(A2, FIND("-",A2)-1), and everything after it is MID(A2, FIND("-",A2)+1, LEN(A2)).

Tidying

TRIM removes spaces at both ends and reduces runs of spaces to one. UPPER, LOWER and PROPER change case. SUBSTITUTE(text, old, new) replaces text, and an empty new text deletes the old one.

Numbers that arrive as text are ignored by SUM. VALUE turns them into numbers, and TRIM first if there are stray spaces: VALUE(TRIM(A2)).

Joining

CONCAT joins its arguments in order. TEXTJOIN(delimiter, ignore_empty, range) joins a whole range with a separator and can skip empty cells, which avoids doubled commas.

Practise it

Module 5, Text cleanup, has 20 tasks on this, each checked on hidden data: open module 5. You can also try formulas in the sandbox.

Related guides