Files
Code
User Form: frmNames
Sub main()
frmNames.Show
End Sub
debugging1
Dim strName As String
Dim strFirstName As String
Dim strLastName As String
Dim intSpaceLocation As Integer
Dim intLength As Integer
Dim i As Integer
Private Sub cmdAdd_Click()
lstName.AddItem txtName.Text
End Sub
Private Sub cmdFormat_Click()
i = 0
While i < lstName.ListCount
strName = lstName.List(i)
If InStr(1, strName, ",") = 0 Then
Call FirstNameFirst
Else
Call LastNameFirst
End If
i = i + 1
Wend
End Sub
Sub FirstNameFirst()
On Error Resume Next
intSpaceLocation = InStr(1, lstName.List(i), " ")
intLength = Len(strName)
strFirstName = Left(strName, intSpaceLocation - 1)
strLastName = Mid(strName, intSpaceLocation + 1, intLength)
strName = strLastName & ", " & strFirstName
lstName.List(i) = strName
End Sub
Sub LastNameFirst()
intSpaceLocation = InStr(1, lstName.List(i), " ")
intLength = Len(strName)
strLastName = Left(strName, intSpaceLocation - 2)
strFirstName = Mid(strName, intSpaceLocation + 1, intLength)
strName = strFirstName & " " & strLastName
lstName.List(i) = strName
End Sub
Private Sub UserForm_Initialize()
lstName.AddItem "Gargarin, Yuri"
lstName.AddItem "Armstrong, Neil"
lstName.AddItem "Aldrin, Buzz"
lstName.AddItem "John Glenn"
lstName.AddItem "Alan Shepard"
End Sub