WallStreetMojo

WallStreetMojo

WallStreetMojo

MENUMENU
  • Free Tutorials
  • Certification Courses
  • Excel VBA All in One Bundle
  • Login
Home » Excel, VBA & Power BI » Learn VBA » VBA StrConv

VBA StrConv

Excel VBA StrConv Function

StrConv function in VBA is categorized under string functions which is a conversion function, the use of this function is that it changes the case of the string with the input provided by the developer, the arguments of this function are the string and the input for case like 1 to change the string to lowercase.

StrConv stands for “String Conversion.” Using this VBA function, we can convert the supplied string to the specified format. One thing you need to understand here is we can use this formula as a VBA function only, not as an Excel worksheet function. In this article, we will take a tour of complete detailed examples of the “VBA StrConv” formula.

Ok, 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 we need to do. We have a wide variety of options here below is the list of conversions we can perform.

  • vbUpperCase or 1: This option converts the supplied Text value to Upper case character. This 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 Lower case character in excel. This 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 will is converted to upper case, and all the remaining letters are converted to lower case. 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: This 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. This will not use 99% of the time.

VBA StrConv

Examples of StrConv Function in VBA

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

Example #1

Now take a look at the example of converting the string to UPPER CASE character. I am using the word “Excel VBA” here. Below is the VBA code.

Popular Course in this category
Sale
VBA Training (3 Courses, 12+ Projects)
4.6 (247 ratings)
3 Courses | 12 Hands-on Projects | 43+ Hours | Full Lifetime Access | Certificate of Completion
View Course

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

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

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

VBA StrConv Example 1-1

Example #2

Now take a look at the same string with lower case 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

This will convert the string “Excel VBA” to a lower case.

You can run manually or through excel shortcut key F5. Below is the result of the same.

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

This will convert the string “Excel VBA” to a proper case. Every first letter of the string is upper case, and every letter after space is also converted to upper case, and all the remaining characters will be converted to lower case. Below is the result of the same.

Example 3-1

Example #4

Now take a look at the example of Unicode character. 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

This 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 has been a guide to VBA StrConv. Here we learn how to use 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 –

  • VBA Operators
  • VBA Charts
  • VBA Boolean Operator
  • VBA End
7 Shares
Share
Tweet
Share
VBA Training (3 Courses, 12+ Projects)
  • 3 Courses
  • 12 Hands-on Projects
  • 43+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>
Primary Sidebar
Footer
COMPANY
About
Reviews
Contact
Privacy
Terms of Service
RESOURCES
Blog
Free Courses
Free Tutorials
Investment Banking Tutorials
Financial Modeling Tutorials
Excel Tutorials
Accounting Tutorials
Financial Statement Analysis
COURSES
All Courses
Financial Analyst All in One Course
Investment Banking Course
Financial Modeling Course
Private Equity Course
Venture Capital Course
Excel All in One Course

Copyright © 2021. CFA Institute Does Not Endorse, Promote, Or Warrant The Accuracy Or Quality Of WallStreetMojo. CFA® And Chartered Financial Analyst® Are Registered Trademarks Owned By CFA Institute.
Return to top

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Book Your One Instructor : One Learner Free Class
Let’s Get Started
Please select the batch
Saturday - Sunday 9 am IST to 5 pm IST
Saturday - Sunday 9 am IST to 5 pm IST

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Login

Forgot Password?

WallStreetMojo

Download VBA StrConv Function Template

New Year Offer - VBA Training Course (6 courses, 35+ hours video) View More