• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Separate First and Last name

Hi,
I want to split the first and last names in a text box entry. I'm using the following code, but it is not working as intended.

Code:
Private Sub Arec7_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim myString As String
myString = Me.Arec7.Value
myString = StrConv(Left(Me.Arec7.Value, 1) & " " & Mid(Me.Arec7.Value, 2), vbProperCase)
End Sub
The name of the text box is Arec7.
The above code should split the first and last names and put them in proper case but this is not happening. What seems to be wrong ???
Any help would be appreciated.
Regards,
Maneesh
 
Whats wrong with
Code:
Private Sub arec7_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  Dim myString As String
  myString = Left(Me.arec7.Text, 1) & " " & Mid(Me.arec7.Text, 2)
  'Debug.Print myString
 
End Sub
 
Hi Hui,
I do not know why this code does not work.
I have attached a snapshot of the immediate window. This code splits the first letter and separates the letters that follow, which is not what I intend it to do.
What's wrong here ???
Regards,
Maneesh

Whats wrong with
Code:
Private Sub arec7_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  Dim myString As String
  myString = Left(Me.arec7.Text, 1) & " " & Mid(Me.arec7.Text, 2)
  'Debug.Print myString

End Sub
 

Attachments

  • Capture.PNG
    Capture.PNG
    2.5 KB · Views: 4
NA
Hi Hui,
I do not know why this code does not work.
I have attached a snapshot of the immediate window. This code splits the first letter and separates the letters that follow, which is not what I intend it to do.
What's wrong here ???
Regards,
Maneesh
Anyone, please help with the following post. What seems to be wrong with the code and why is it not working ??
Regards,
Maneesh
 
For instance, I want the name, maneeshmassey look like "Maneesh Massey" (without the double quotes) when the user types in his/her name. How would this be accomplished ??
Anyone please help!
Regards,
Maneesh
 
What are some ways to make the first and last name into proper case like for example, tom croft as Tom Croft.
Please help.
Regards,
Maneesh
 
The left() command gets the text starting at the left-most character, and going to the right for the number of characters specified - you have 1 specified, so it only grabs the left-most character. Unless everyone has the same number of letters in their first and last name, your code won't work like you have it. You need to supply more information to the code.
 
Code:
Sub Demo()
    MsgBox Application.Proper("winston leonard spencer churchill")
End Sub
Hi, Maneesh Massey!
Taking Marc L's example, how would you identify first and last when full names have more than one word? This is the main issue to define, previously to any code analysis or change.
Regards!
 
Back
Top