Capitalize first letter of first word only

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
Is there a way I can capitalize the first letter of the first word only in a Userform Textbox, rather than every word?

Better still, how about what I would call true propercase, where the first word of each sentence is capitalized, rather than the usual propercase which in my view is not accurate because it capitalizes every word.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
well its in the Office library so its one of the Microsoft frustration. I have the library and my VBE can see the function, reference the library, but can't use it? Why Microsoft? Why!
 
Upvote 0
Thanks guys - found this though which has done the trick for anyone else who is tinkering......

Capitilize First Letter & After Full Stop/Period in TextBox
That code is not "perfect"...

First, type a couple of letters and then move the text cursor back to the beginning of the text and type a lower case letter... the originally upper cased letter, which is now the second character, will remain upper cased.

Second, that code will not handle multiple paragraphs (created after hitting the Enter Key, assuming you set the TextBox's EnterKeyBehavior to True) correctly... the first letter of the second and subsequent paragraphs will remain lower case.

I have not tested that code further to see if it has any other anomalies or not. I think I agree with the statement Dave Hawley made in the linked thread, namely, I would use the Exit event instead. For the function I posted in Message #9, the Exit event procedure code would look like this...
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  TextBox1.Text = SentenceCase(TextBox1.Text)
End Sub
 
Upvote 0
That code is not "perfect"...
Two more places the code at the link you posted fails...

First, copy a group of upper case text from somewhere, then run/show the UserForm, type some text in, then paste what you copied earlier into the text at any location... the upper case text you copied remains upper case after being pasted in.

Second, type a single letter (works with more letters, but a single letter is more dramatic), then say you realize it was the wrong letter, so you press the backspace key to delete it so that you can type the correct letter... Boom!... the program crashes instead.

It is not easy to write a perfect, on-the-fly parser as I believe I have demonstrated in this and my previous posts.
 
Upvote 0
Upvote 0
Guys - I'm very grateful and will test the suggestions.

Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,972
Messages
6,128,035
Members
449,414
Latest member
sameri

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