Textbox Last Name Multiple Capital Letters

CokeOrCrack

Board Regular
Joined
Dec 13, 2015
Messages
81
- Within a userform, I have a textbox in which applicants type their last name
- Some last names contain multiple capital letters (e.g. "McDonald")
- The Proper Case function only capitalizes the first letter of each name and forces the remainder as lower case

Question
- Is there a way to capitalize multiple letters within the textbox, but not all the letters?

Notes
- My current code is proper case and will not allow for a capital internally
Code:
Private Sub tbLastName_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    tbLastName.Value = Application.WorksheetFunction.Proper(tbLastName.Value)
    tbLastName.Value = Application.Trim(tbLastName.Value)
    If tbLastName.Value = vbNullString Then
        MsgBox "Enter Last Name"
        Cancel = True
    End If
End Sub

Thanks

OJ
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Use as string variable to check for the instances you want and then assign the modified string to the text box. Also there is a VBA method to substitute to Proper Case so I used that instead.

Code:
Private Sub tbLastName_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim s As String
    s = Application.Trim(StrConv(tbLastName.Value, vbProperCase))
    If Left(s, 2) = "Mc" Then Mid(s, 3, 1) = UCase(Mid(s, 3, 1))
    If Left(s, 3) = "Mac" Then Mid(s, 4, 1) = UCase(Mid(s, 4, 1))
    tbLastName.Value = s
    If tbLastName.Value = vbNullString Then
        MsgBox "Enter Last Name"
        Cancel = True
    End If
End Sub
 
Upvote 0
Use as string variable to check for the instances you want and then assign the modified string to the text box. Also there is a VBA method to substitute to Proper Case so I used that instead.

Code:
Private Sub tbLastName_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim s As String
    s = Application.Trim(StrConv(tbLastName.Value, vbProperCase))
    If Left(s, 2) = "Mc" Then Mid(s, 3, 1) = UCase(Mid(s, 3, 1))
    If Left(s, 3) = "Mac" Then Mid(s, 4, 1) = UCase(Mid(s, 4, 1))
    tbLastName.Value = s
    If tbLastName.Value = vbNullString Then
        MsgBox "Enter Last Name"
        Cancel = True
    End If
End Sub
Handling Mac that way could lead to problems with other names. A few years back, Trenton NJ (USA), the capital city of NJ, had a mayor named Tony Mack... your code would make his last name MacK. And I am sure there are more names starting with Mac that do not have an upper case fourth letter. Personally, I don't think there is an automatic way to handle names beginning with Mac.
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top