VBA StrConv

Article byJeevan A Y
Reviewed byDheeraj Vaidya, CFA, FRM

Excel VBA StrConv Function

The StrConv function in VBA comes under String functions, a conversion function. One may use this function because it changes the case of the string with the input provided by the developer. In addition, the arguments of this function are the string. So, for example, the input for a case like 1 is to change the string to lowercase.

StrConv stands for “String Conversion.” We can convert the supplied string to the specified format using this VBA functionVBA FunctionVBA functions serve the primary purpose to carry out specific calculations and to return a value. Therefore, in VBA, we use syntax to specify the parameters and data type while defining the function. Such functions are called user-defined functions.read more. You need to understand that we can use this formula as a VBA function only, not as an Excel worksheet function. This article will tour detailed examples of the “VBA StrConv” formula.

Look at the syntax of the StrConv function.

VBA StrConv syntax

String: This is nothing but the text we are trying to convert.

Conversion: What kind of conversion do we need to do? We have a wide variety of options. Here, below is the list of conversions we can perform.

Even though we have several other options with the Conversion argument above, three are good enough for us.

LCID: This is the Locale ID. By default, it takes the system ID. It will not use 99% of the time.

VBA StrConv

You are free to use this image on your website, templates, etc, Please provide us with an attribution linkHow to Provide Attribution?Article Link to be Hyperlinked
For eg:
Source: VBA StrConv (wallstreetmojo.com)

You are free to use this image on your website, templates, etc, Please provide us with an attribution linkHow to Provide Attribution?Article Link to be Hyperlinked
For eg:
Source: VBA StrConv (wallstreetmojo.com)

Examples of StrConv Function in VBA

You can download this VBA StrConv Function Template here – VBA StrConv Function Template

Example #1

Now, look at the example of converting the string to the UPPER CASE character. We are using the word “Excel VBA” here. Below is the VBA codeVBA CodeVBA code refers to a set of instructions written by the user in the Visual Basic Applications programming language on a Visual Basic Editor (VBE) to perform a specific task.read more.

Code:

Sub StrConv_Example1()

    Dim TextValues As String
    Dim Result As String

    TextValues = "Excel vba"

    Result = StrConv(TextValues, vbUpperCase)

    MsgBox Result

End Sub
VBA StrConv Example 1

It will convert the string “Excel VBA” to upper case.

Run this code using the F5 key or manually and see the result.

VBA StrConv Example 1-1

–>> If you want to learn Excel VBA professionally, then our VBA Basic Course (16+ hours) is the perfect solution. In our Basic Excel VBA course you learn the skill of automating tasks using Variables, Data Types, Ranges, and Cells in VBA. Master Control Structures, including Conditional Statements and Loops, and discover techniques for manipulating data through sorting, filtering, and formatting. By the end of the course, you will be able to apply your acquired skills to real projects, culminating in an Excel VBA project which will solidify your ability to create efficient, automated solutions.

Example #2

Now, take a look at the same string with lowercase conversion. Below is the code.

Code:

Sub StrConv_Example2()

    Dim TextValues As String
    Dim Result As String

    TextValues = "Excel vba"

    Result = StrConv(TextValues, vbLowerCase)

    MsgBox Result

End Sub
VBA StrConv Example 2

It will convert the string “Excel VBA” to a lowercase.

You can run it manually or through excel shortcut keyExcel Shortcut KeyAn Excel shortcut is a technique of performing a manual task in a quicker way.read more F5. Below is the result.

VBA StrConv Example 2-1

Example #3

Now, take a look at the same string with proper case conversion. Below is the code.

Code:

Sub StrConv_Example3()

    Dim TextValues As String
    Dim Result As String

    TextValues = "Excel vba"

    Result = StrConv(TextValues, vbProperCase)

    MsgBox Result

End Sub
Example 3

It will convert the string “Excel VBA” to a proper case. Every first letter of the string is upper case. Moreover, it converts every letter after space to uppercase. All the remaining characters convert to lowercase. Below is the result of the same.

Example 3-1

Example #4

Now, look at the Unicode character’s example. Look at the below code.

Code:

Sub StrConv_Example4()

  Dim i As Long
  Dim x() As Byte
  x = StrConv("ExcelVBA", vbFromUnicode)
  For i = 0 To UBound(x)
  Debug.Print x(i)
 Next

End Sub

It will print all the Unicode characters to the immediate window.

Example 4

In ASCII code, “E” Unicode is 69, “x” Unicode is 120, and so on. Like this, using VBA StrConv, we can convert the string to Unicode.

Example 4-1

Recommended Articles

This article has been a guide to VBA StrConv. Here, we learn how to use the VBA StrConv function to convert the supplied string to the specified format, along with practical examples and a downloadable Excel template. Below you can find some useful Excel VBA articles: –