Extract the last substring from a cell

后端 未结 9 1840
逝去的感伤
逝去的感伤 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:22
    Right(A1, Len(A1)-Find("(asterisk)",Substitute(A1, "(space)","(asterisk)",Len(A1)-Len(Substitute(A1,"(space)", "(no space)")))))
    

    Try this. Hope it works.

    0 讨论(0)
  • 2020-12-01 08:28

    The answer provided by @Jean provides a working but obscure solution (although it doesn't handle trailing spaces)

    As an alternative consider a vba user defined function (UDF)

    Function RightWord(r As Range) As Variant
        Dim s As String
        s = Trim(r.Value)
        RightWord = Mid(s, InStrRev(s, " ") + 1)
    End Function
    

    Use in sheet as
    =RightWord(A2)

    0 讨论(0)
  • 2020-12-01 08:31

    Simpler would be: =TRIM(RIGHT(SUBSTITUTE(TRIM(A2)," ",REPT(" ",99)),99))

    You can use A2 in place of TRIM(A2) if you are sure that your data doesn't contain any unwanted spaces.

    Based on concept explained by Rick Rothstein: http://www.excelfox.com/forum/showthread.php/333-Get-Field-from-Delimited-Text-String

    Sorry for being necroposter!

    0 讨论(0)
提交回复
热议问题