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
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.