Use MsgBox(), InStr(), Left(), Right() and Len() to read the first name and last name : InStr « String Functions « VBA / Excel / Access / Word






Use MsgBox(), InStr(), Left(), Right() and Len() to read the first name and last name

 
Sub AboutUser()
    Dim fullName As String
    Dim firstName As String
    Dim lastName As String
    Dim space As Integer

    fullName = InputBox("Enter first and last name:")

    space = InStr(fullName, " ")
    firstName = Left(fullName, space - 1)
    lastName = Right(fullName, Len(fullName) - space)
    Debug.Print lastName & ", " & firstName
End Sub

 








Related examples in the same category