Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA String and capital letters 1

Status
Not open for further replies.

luke99

MIS
Dec 20, 2002
8
GB
HI again, i was wondering if anyone could help me do this bit of code. i want it to change the first letter to upper case. i know that left$(String, 1) but how do i make it capital and then update the string?

thanks.

Luke99
 
luke99,

Try this:

Code:
MyString = StrConv(MyString, vbProperCase)

Will convert each word in MyString to have an initial capital letter. Of course, you can supply a one word argument if that is all you need capitalized, then tack it onto another string, if you don't want every word capitalized.


HTH
Mike
 
You should be able to use something like this:
Code:
Function Proper(AString As String) As String
'Convert first character of AString to upper case
Dim FirstChar As String
FirstChar = Left$(AString, 1)
FirstChar = Chr(Asc(FirstChar) And &HDF)
Proper = FirstChar + Mid$(AString, 2, Len(AString) - 1)
End Function
 
Thanks Mike. That's much better. I looked in the help for "Proper" and couldn't find a reference to that function. I also looked under "Case" with the same result. After your post I looked again with "Proper Case" and StrConv Function was in the list. Go figure.
 
Thanks guy, all done. i love this forum, i have only been a member for 3 days or so. And the response has been great, thanks to you.

Luke99
 
Zathras,

My experience is that the VBA Help is pretty hit & miss. Some topics are covered fairly in-depth while others leave too many questions unanswered. Also, as you experienced, searching for certain topics, even when you know they exist, can be quite frustrating.

Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top