Function SplitText(ByVal strText As String) As String
Dim intPos As Integer
intPos = InStrRev(strText, " ")
SplitText = Mid(strText, intPos + 1)
End Function
Function GetFirstPartString(ByVal strText As String) As String
Dim intPos As Integer
intPos = InStrRev(strText, " ")
GetFirstPartString = Left(strText, intPos - 1)
End Function
[SIZE=1]let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Inserted Text Before Delimiter" = Table.AddColumn(Source, "Text Before Delimiter", each Text.BeforeDelimiter([raw data], " ", 1), type text),
#"Inserted Text After Delimiter" = Table.AddColumn(#"Inserted Text Before Delimiter", "Text After Delimiter", each Text.AfterDelimiter([raw data], " ", 1), type text),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Text After Delimiter",{"raw data"})
in
#"Removed Columns"[/SIZE]
Sub leonardo()
Dim Cl As Range
For Each Cl In Range("A2", Range("A" & Rows.count).End(xlUp))
On Error Resume Next
Cl.Offset(, 1) = Trim(Mid(Cl, InStr(InStr(1, Cl, " ") + 1, Cl, " ")))
On Error GoTo 0
Cl = Trim(Replace(Cl, Cl.Offset(, 1), ""))
Next Cl
End Sub
Sub Leonardo2()
With Range("A2", Range("A" & Rows.count).End(xlUp))
.Offset(, 1).Value = Evaluate(Replace("iferror(right(@,len(@)-find(""|"",substitute(@,"" "",""|"",2))),"""")", "@", .Address))
.Value = Evaluate("if({1},substitute(" & .Address & "," & .Offset(, 1).Address & ",""""))")
End With
End Sub
Hi Leonardo,
https://support.office.com/en-us/ar...s-Wizard-30B14928-5550-41F5-97CA-7A3E9C363ED7
Or you can use those two UDF
Code:Function SplitText(ByVal strText As String) As String Dim intPos As Integer intPos = InStrRev(strText, " ") SplitText = Mid(strText, intPos + 1) End Function
Code:Function GetFirstPartString(ByVal strText As String) As String Dim intPos As Integer intPos = InStrRev(strText, " ") GetFirstPartString = Left(strText, intPos - 1) End Function
HTH
Here is another way to write a loopless macro for this question...Or without a loopCode:Sub Leonardo2() With Range("A2", Range("A" & Rows.count).End(xlUp)) .Offset(, 1).Value = Evaluate(Replace("iferror(right(@,len(@)-find(""|"",substitute(@,"" "",""|"",2))),"""")", "@", .Address)) .Value = Evaluate("if({1},substitute(" & .Address & "," & .Offset(, 1).Address & ",""""))") End With End Sub
[table="width: 500"]
[tr]
[td]Sub Leonardo2()
Application.ScreenUpdating = False
With Range("A2", Range("A" & Rows.Count).End(xlUp))
.Value = Evaluate("IF({1},SUBSTITUTE(" & .Address & ","" "",CHAR(1),2))")
.TextToColumns , xlDelimited, , , False, False, False, False, True, Chr(1)
End With
Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]