I wanted to write a function to capitalize the first character of every word. For example, I want to change "cell address" to "Cell Address". Before I started the function, I was thinking perhaps there already has a easy way to do that. Luckily, I did a search in the Google and found this: StrConv
This is the function I've written:
Public Function CapitalizeFirstCharacter(ByVal Value As String) As String
' Make the whole string lower case, then only capitalize the first character
CapitalizeFirstCharacter = StrConv(LCase$(Value), vbProperCase)
End Function
Syntax:
StrConv (String, conversion[, LCID])
String - required. String expression to be converted.
conversion - required. Integer. The sum of values specifying the type of conversion to perform.
LCID - optional. The LocaleID, if different than the system LocaleID. (default: system LocaleID)
conversion argument:
Constants | Value | Description |
vbUpperCase | 1 | Convert to uppercase |
vbLowerCase | 2 | Convert to lowercase |
vbProperCase | 3 | Convert the first letter of every word in string to uppercase |
No comments:
Post a Comment