Split text in column using second space from left

Leonardo

Board Regular
Joined
Nov 8, 2011
Messages
57
Is there a convenient way to split text in to two columns using the second space from the left. The text is not fixed length. There are no potential delimiters other than space characters.
I am using Excel 2016 on a Windows 10.
Thank you
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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
 
Last edited:
Upvote 0
you can try PowerQuery aka Get&Transform

Code:
[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]
 
Upvote 0
Another option
Code:
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
 
Upvote 0
Or without a loop
Code:
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
 
Upvote 0
Thank you Silentwolf, sandy66 and Fluff for your replies. I'm only marginally familiar with macros and I needed to get this worksheet for tomorrow morning. I did a brute force parse using text to columns and FlashFill. That is not adequate for the long term and I will review your macros and see if I can figure out how to implement one of them. I'm sure I will have more questions as I try to work with the macros.

Thanks again,

Leonardo
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
 
Last edited:
Upvote 0
Or without a loop
Code:
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
Here is another way to write a loopless macro for this question...
Code:
[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]
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top