Strconv function another option to convert String to Lower Case, Upper case even Proper case with more option available.
Syntax : StrConv(String, Constant/Value), Returns : String
The Conversion setting as below table:
Constant | Value | Function detail |
vbUpperCase | 1 | Converts the string to uppercase characters. |
vbLowerCase | 2 | Converts the string to lowercase characters. |
vbProperCase | 3 | Converts the first letter of every word in a string to uppercase. |
vbWide | 4 | Converts narrow (single-byte) characters in a string to wide (double-byte) characters. |
vbNarrow | 8 | Converts wide (double-byte) characters in a string to narrow (single-byte) characters. |
vbKatakana | 16 | Converts Hiragana characters in a string to Katakana characters. |
vbHiragana | 32 | Converts Katakana characters in a string to Hiragana characters. |
vbUnicode | 64 | Converts the string to Unicode using the default code page of the system. (Not available on the Macintosh.) |
vbFromUnicode | 128 | Converts the string from Unicode to the default code page of the system. (Not available on the Macintosh.) |
For example if we wish to convert from Lower case to Upper case then we use Syntax:
StrCov(String,1) or StrCov(String,vbUpperCase) the result will the same.
VBA Vode:
Option Explicit
Sub Examples_Strconv_Function()
Dim StrTxtA As String
StrTxtA = "My Car Number PRS123"
Debug.Print StrConv(StrTxtA, 1) 'MY CAR NUMBER PRS123
Debug.Print StrConv(StrTxtA, 2) 'my car number prs123
Debug.Print StrConv(StrTxtA, 3) 'My Car Number Prs123
'Or
Debug.Print StrConv(StrTxtA, vbUpperCase) 'MY CAR NUMBER PRS123
Debug.Print StrConv(StrTxtA, vbLowerCase) 'my car number prs123
Debug.Print StrConv(StrTxtA, vbProperCase) 'My Car Number Prs123
End Sub
Sub Examples_Strconv_Function()
Dim StrTxtA As String
StrTxtA = "My Car Number PRS123"
Debug.Print StrConv(StrTxtA, 1) 'MY CAR NUMBER PRS123
Debug.Print StrConv(StrTxtA, 2) 'my car number prs123
Debug.Print StrConv(StrTxtA, 3) 'My Car Number Prs123
'Or
Debug.Print StrConv(StrTxtA, vbUpperCase) 'MY CAR NUMBER PRS123
Debug.Print StrConv(StrTxtA, vbLowerCase) 'my car number prs123
Debug.Print StrConv(StrTxtA, vbProperCase) 'My Car Number Prs123
End Sub
Note:
Basically to convert String to Upper case we use Ucase function, String to Lower case we use Lcase function and to convert String to Proper case then we use StrConv function and the rest is not so importance.
excel programming, excel vba at below links.
Microsoft Reference-Strconv-function
Other Reference-Strconv-function
Leave your comments if you have any request.
Practice makes perfect.
Thank You.
No comments:
Post a Comment