Extract the last substring from a cell

后端 未结 9 1857
逝去的感伤
逝去的感伤 2020-12-01 07:57

I have names in a column. I need to split just the last names from that column into another column.

The last name is delimited by a space from the right side.

9条回答
  •  既然无缘
    2020-12-01 08:19

    If you want to get the second to last word in a text, you can use this macro as a function in your spreadsheet:

    Public Function Get2ndText(S As String) As String
    
    Dim sArr() As String
    Dim i As Integer
    sArr = Split(S, " ")
    
    'get the next to the last string
    i = UBound(sArr) - 1
    Get2ndText = sArr(i)
    
    End Function
    

    Then in your spreadsheet B1 as the text:

    CURRENT OWNER 915 BROADWAY ST HOUSTON TX 77012-2126
    

    in B2 your formula would be:

    =Get2ndText(B1)
    

    The result would be

    TX
    

提交回复
热议问题