Elite Membership

VBA StrConv

Written by Jeevan A Y Jeevan A Y Freelance Writer Jeevan, a seasoned data expert with 7 years in MIS reporting, excels in Advanced Excel, VBA, Power BI, and SQL. Currently an Assistant Manager MIS, his insightful data storytelling drives swift decision-making. 7+ years of experience MBA (Finance & Marketing) MIS Reporting View Full Profile
Reviewed by Dheeraj Vaidya, CFA, FRM Dheeraj Vaidya, CFA, FRM Content Reviewer & Course Director Dheeraj is a former J.P. Morgan and CLSA Equity Analyst with nearly two decades of experience in financial modeling, valuation, equity research, and corporate finance. He specializes in helping students and professionals develop practical and in-demand finance skills through structured and AI-powered, 20+ Years of experience CFA, FRM, IIT Delhi, IIM Lucknow Financial Modeling View Full Profile
Updated Dec 23, 2024
Read Time 4 min

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.

Download FREE VBA StrConv In Excel Template and Follow Along!
Download Excel Template
VBA StrConv

StrConv stands for โ€œString Conversion.โ€ย We can convert the supplied string to the specified format using this VBA function. 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.

Key Takeaways

  • vbUpperCase or 1: This option converts the supplied Text value to upper case character. It works similarly to the UCASE function. For example, if you supply the word โ€œExcel,โ€ it will convert to โ€œEXCEL.โ€
  • vbLowerCase or 2: This option converts the supplied Text value to lowercase character in excel. It works similarly to the LCASE function. For example, if you supply the word โ€œExcel,โ€ it will convert to โ€œexcel.โ€
  • vbProperCase or 3: This option converts the supplied Text value to the proper case character. Every first character of the word converts to uppercase. All the remaining letters convert to lowercase. For example, if you supply the word โ€œexcEL,โ€ it will convert to โ€œExcel.โ€
  • vbUniCode or 64: This option converts the string to Unicode code.
  • vbFromUnicode or 128: It converts the string Unicode to the default system code.

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.

Examples of StrConv Function in VBA

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 code.

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

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 key 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: –