I'm playing around on how to get last name in the string.
Below is my current code and it is working. I want to know if there is another way to do it.

    strMsg = "John Doe"
    length = Len(strMsg)

    For i = 0 To length
        char = Right(strMsg, i + 1)
            If Left(char, 1) = " " Then
                LastName = Trim(char)
                Debug.Print LastName
                Exit For
            End If
    Next i

Another way round to write this logic after did some 'Google'd

    strMsg = "John Doe"

    For i = 0 To Len(strMsg)
        char = Mid(strMsg, Len(strMsg) - (0 + i), Len(strMsg))
            If Left(char, 1) = " " Then
                LastName = Trim(char)
                Debug.Print LastName
                Exit For
            End If
    Next i

Any other ideas?

Using Array :

strmsg = "John Doe der"
Dim a() As String

a = Split(strmsg, " ")
Debug.Print a(UBound(a))
Comments
good example
This question has already been answered. Start a new discussion instead.