VBA STRCONV Function

VBA StrConv Function in Excel

VBA StrConv function in Excel is categorized as a Text/String function in VBA. It is a built-in function in MS Office Excel. It converts a string to a specified format(vbUpperCase, vbLowerCase, vbUnicode, vbWide, vbNarrow, vbProperCase, etc.). It has two required parameters and one optional parameter. If string is an empty string, then function returns empty string. This function could be used as a VBA function and can’t be used as a Excel Worksheet function.

The StrConv function can be used in either procedure or function in a VBA editor window in Excel. We can use this VBA StrConv function any number of times in any number of procedures or functions. In the following section we learn what is the syntax and parameters of the StrConv function, where we can use this StrConv function and real-time examples in VBA.

Syntax of VBA StrConv Function

The syntax of the VBA StrConv function is

StrConv(String, Conversion, [LocaleID])

Note: This StrConv function returns a string.

Parameters or Arguments

This function has two mandatory parameter and one optional parameters for the StrConv Function.
Where
String: The String is a mandatory argument. It represents a string that you want to search within.
Conversion: The Conversion is a required argument. It represents the type of conversion to be perform. Here are the following conversion values.

VBA Constant Value Description
vbUpperCase 1 Convert the string to upper case letters.
vbLowerCase 2 Convert the string to lower case letters.
vbProperCase 3 Convert the first character of every word to upper case and all other characters to lower case.
vbWide 4 Convert narrow characters to wide characters.
vbNarrow 8 Convert wide characters to narrow characters.
vbKatakana 16 Convert the Hiragana characters to the Katakana characters.
vbHiragana 32 Convert Katakana characters to Hiragana characters.
vbUnicode 64 Convert the string to Unicode.
vbFromUnicode 128 Convert the string from Unicode to the default code of the system.

LocaleID: The LocaleID is an optional argument. It represents the LocaleID. It is different from system LocaleID. If you ignore this argument, then it considers default system LocaleID.

Where we can apply or use the VBA StrConv Function?

We can use this VBA StrConv function in MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

Example 1: Convert the string to Upper case letters

Here is a simple example of the VBA StrConv function. This below example macro uses the StrConv function and converts the given string to upper case letters.

'Convert the string to Upper case letters
Sub VBA_StrConv_Function_Ex1()

    Dim sString As String
    Dim sSubString As String
    
    sString = "Vbaf1.com"
    
    sSubString = StrConv(sString, vbUpperCase)
    
    MsgBox "The given string to upper case is :" & sSubString, vbInformation, "VBA StrConv Function"

End Sub

Output:Here is the screen shot of the first example output.
VBA StrConv Function

Example 2: Convert the string to Proper case letters

Here is another example of the VBA StrConv function. This below example code uses the StrConv function and converts the given string to proper case letters.

'Convert the string to Proper case letters
Sub VBA_StrConv_Function_Ex2()

    Dim sString As String, sSubString As String
    
    sString = "vbaf1"
    
    sSubString = StrConv(sString, vbProperCase)
    
    MsgBox "The given string to proper case is :" & sSubString, vbInformation, "VBA StrConv Function"

End Sub

Output:Here is the screen shot of the second example output.
VBA StrConv Function

Example 3: Convert the string to lower case letters

Here is a simple example of the VBA StrConv function. This below example macro uses the StrConv function and converts the given string to lower case letters.

'Convert the string to lower case letters
Sub VBA_StrConv_Function_Ex3()

    Dim sString As String
    Dim sSubString As String
    
    sString = "VBAF1.COM"
    
    sSubString = StrConv(sString, vbLowerCase)
    
    MsgBox "The given string in lower case is :" & sSubString, vbInformation, "VBA StrConv Function"

End Sub

Output:Here is the screen shot of the third example output.
VBA StrConv Function

Example 4: Convert the string to Unicode

Here is one more example of the VBA StrConv function. This below example procedure uses the StrConv function and converts the given string to Unicode letters.

'Convert the string to Unicode
Sub VBA_StrConv_Function_Ex4()

    Dim sString As String, sSubString As String
    Dim iCnt As Integer
    Dim aString() As Byte
    
    sString = "Life is beautiful"
    
    aString = StrConv(sString, vbUnicode)
    
    For iCnt = 0 To UBound(aString)
          sSubString = sSubString & aString(iCnt)
    Next
    
    MsgBox "The given string in Unicode is : " & sSubString, vbInformation, "VBA StrConv Function"

End Sub

Output:Here is the screen shot of the fourth example output.
VBA StrConv Function

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays in Excel Blog

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers

Leave a Reply