View Single Post
 
Old 06-15-2018, 12:59 PM
d4okeefe d4okeefe is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Apr 2013
Posts: 77
d4okeefe is on a distinguished road
Default

Code:
Sub get_last_word_in_string()
    Dim strAttorneyName: strAttorneyName = "My name is Smith"
    Dim arr, last_name As String
    arr = Split(strAttorneyName, " ")
    last_name = arr(UBound(arr))
End Sub
Or, the rather complicated ...
Code:
Sub get_last_word_in_string()
    Dim strAttorneyName: strAttorneyName = "My name is Smith"
    Dim last_name as String
    last_name = Right(strAttorneyName, _
        Len(strAttorneyName) - _
        InStrRev(strAttorneyName, " ", _
        Len(strAttorneyName) - 1))
End Sub
Reply With Quote