I'm looking for a macro that could split text based on character "-". I have something like product ID made from many pieces separeted with "-". Those pieces have not always the same length but I always have the same number of them (always have four "-").
This ID is in one cell and it looks like this:
02-aaaa-mbd-98-2a.
As an output I want to have 02, aaaa, mbd, 98 and 2a in separeted cells
more information here
Check out link for help with splitting text-to-columns, if you want a macro for this, simply use "Record Macro"
You can use the following:
Split Function as an UDF
When cell
A1
has the desired input, you use the function=EXTRACTELEMENT($A$1;1;"-")
on cellB1
and=EXTRACTELEMENT($A$1;2;"-")
on cellC1
and so on.The result:
Regex
The Regex101 and the code for values on column A:
The result is the same image as using an UDF.