Reputation: 7
How would one split a cell containing string with different delimiters?
Cell A2 has "14:5-18:24"
into cells b2 to e2:
14 5 18 24
Upvotes: 0
Views: 100
Reputation: 60174
You can also do this in Power Query:
M Code
let
Source = Excel.CurrentWorkbook(){[Name="Table9"]}[Content],
Typed = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
Split = Table.SplitColumn(Typed,"Column1",Splitter.SplitTextByAnyDelimiter({":","-"}))
in
Split
To use Power Query
Data => Get&Transform => from Table/Range
Home => Advanced Editor
Upvotes: 0
Reputation: 53136
As a formula (requires Excel 365's Dynamic Array capability)
=IFERROR(TRANSPOSE(FILTERXML("<a><b>"&SUBSTITUTE(SUBSTITUTE(A2,"-",":"),":","</b><b>")&"</b></a>","//b")),"")
As VBA
Sub Demo()
Dim rSrc As Range
Dim rDst As Range
Dim Src As String
Dim Result As Variant
Set rSrc = ActiveSheet.Range("A2")
Set rDst = ActiveSheet.Range("B2")
Src = rSrc.Value2
Result = Split(Replace$(rSrc.Value2, "-", ":"), ":")
With rDst.Resize(1, UBound(Result) - LBound(Result) + 1)
.Value2 = Result ' Places result as strings
.Value2 = .Value2 ' Convert to numbers
End With
End Sub
Upvotes: 1