EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home VBA VBA Resources VBA String and Text Functions VBA StrConv
 

VBA StrConv

Ashwani Jaiswal
Article byAshwani Jaiswal
Madhuri Thakur
Reviewed byMadhuri Thakur

VBA Strconv

VBA Strconv Function

VBA Strconv, where Strconv stands for “String Conversion”. We all know that in VBA if we want to use text then we have to use String function to define variables. With the help of Strconv function in VBA, we can change the text to Upper case, Lower case and Proper Case without selecting the cell where it may belong. The VBA Strconv cannot be used in Excel. But in excel we can change the text of Upper case, Lower case and Proper case with already defined commands.

 

 

Syntax of StrConv in Excel VBA

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

The syntax for the VBA StrConv function in excel is as follows:

VBA StrConv Syntax

As per the syntax of StrConv;

  • String = Set of alphabets and text in any format.
  • Conversion = Type of conversion we want to apply to a selected string.

Different types of Conversions are mentioned below;

  • vbUpperCase (or 1) – This option converts any type of text to Upper.
  • vbLowerCase (or 2) – This option converts any type of text to Lower.
  • vbProperCase (or 2) – This option converts any type of text to Proper Case, which means the first letter of each word will be in Upper case and rest letters will be in Lower case.
  • vbUniCode (or 64) – This converts the text into Unicode.
  • vbFromUniCode (or 128) – This converts Unicode to Default system code which can be anything.

How to Use VBA StrConv in Excel?

We will learn how to use a VBA StrConv Function with few examples in excel.

You can download this VBA Strconv Excel Template here – VBA Strconv Excel Template

Example #1 – VBA StrConv

Step 1: Now open a new Module from Insert.

VBA Strconv Module

Step 2: To convert a text into different case formats we need to define 2 variables. Let’s consider our first variable Input1 as String as shown below.

Code:

Sub VBA_Strconv()

  Dim Input1 As String

End Sub

VBA Strconv example 1.1

Step 3: Now choose another variable and assign it as String. Here, our second variable is Output.

Code:

Sub VBA_Strconv()

  Dim Input1 As String
  Dim Output As String

End Sub

VBA Strconv example 1.2

Step 4: Now assign any text to defined variable Input1. Here we have considered a string of text “VBA string Conversion” which has the first word in Upper case, the second word in Lower case and third word in Proper case.

Code:

Sub VBA_Strconv()

  Dim Input1 As String
  Dim Output As String

  Input1 = "VBA string Conversion"

End Sub

VBA Strconv example 1.3

Step 5: Now in variable Output we will put the values stored in Input1 with the help of StrConv function as shown below.

Code:

Sub VBA_Strconv()

  Dim Input1 As String
  Dim Output As String

  Input1 = "VBA string Conversion"
  Output = StrConv(

End Sub

VBA Strconv example 1.4

Step 6: Now under StrConv function assign Input1 variable and the type of case we want to convert. Let’s choose vbLowerCase first for lower case text as shown below.

Code:

Sub VBA_Strconv()

  Dim Input1 As String
  Dim Output As String

  Input1 = "VBA string Conversion"
  Output = StrConv(Input1, vbLowerCase)

End Sub

 example 1.5

Step 7: Now assign the message box to variable Output to see the result of function StrConv.

Code:

Sub VBA_Strconv()

  Dim Input1 As String
  Dim Output As String

  Input1 = "VBA string Conversion"
  Output = StrConv(Input1, vbLowerCase)

  MsgBox Output

End Sub

example 1.6

Step 8: Once done then compile the code and run it by clicking on the Play button located below the menu bar. We will get a message box with all the letters in Lower case as shown below.

VBA Strconv 1

Example #2 – VBA StrConv

In this example, we will see how vbUpperCase works for the same text which we have chosen in the above example. For this, we will continue using the same code, but we will change the conversion type only in StrConv function.

VBA Strconv example 2.1

Step 1: Now add conversion type in StrConv syntax as “vbUpperCase” as shown below.

Code:

Sub VBA_Strconv2()

  Dim Input1 As String
  Dim Output As String

  Input1 = "VBA String Conversion"

  Output = StrConv(Input1, vbUpperCase)

  MsgBox Output

End Sub

VBA Strconv example 2.1

Step 2: Again compile and run the code. We will see, conversion type vbUpperCase has converted the text stored in Input1 into upper cases as shown below.

VBA StrConv 2

Example #3 – VBA StrConv

In this example, we will see how vbProperCase works for the same text which we have seen in the above examples. Again,

Step 1: We will choose the same code which we have seen in examples.

Code:

Sub VBA_Strconv3()

   Dim Input1 As String
   Dim Output As String

   Input1 = "VBA String Conversion"

   Output = StrConv(Input1, vbProperCase)

   MsgBox Output

End Sub

VBA Strconv example 3.1

Step 2: Now add conversion type in StrConv syntax as “vbProperCase” as shown below.

Code:

Sub VBA_Strconv3()

    Dim Input1 As String
    Dim Output As String

    Input1 = "VBA String Conversion"

    Output = StrConv(Input1, vbProperCase)

   MsgBox Output

End Sub

Example 3.2

Step 3: Again compile and run the code. We will see, conversion type vbProperCase has converted the text stored in Input1 into upper cases as shown below which means the first letter of all the words will be in CAPS and rest of the letters will be small.

VBA Strconv 3

Example #4 – VBA StrConv

In this example, we will the conversion of a string with the help of vbFromUnicode. For this again we would need a module.

Step 1: Now open a new Module from the Insert menu list and start the subcategory of VBA Strconv as shown below.

Code:

Sub VBA_Strconv4()

End Sub

VBA Strconv Example 4.1

Step 2: In a similar way as we have seen in previous examples, we will again use same Variables Input1 and Output. Assign variable Input1 as Long.

Code:

Sub VBA_Strconv4()

Dim Input1 As Long

End Sub

VBA Strconv Example 4.2

Step 3: And assign second variable Output as Byte. This is because we will store Unicode here.

Code:

Sub VBA_Strconv4()

Dim Input1 As Long
Dim Output() As Byte

End Sub

Example 4.3

Step 4: Now in Output variable use Strconv function as shown below. And as per syntax, use any string. We are using the same text which we have seen above and select the conversion type as vbFromUnicode.

Code:

Sub VBA_Strconv4()

Dim Input1 As Long
Dim Output() As Byte

Output = StrConv("VBA String Conversion", vbFromUnicode)

End Sub

Example 4.4

Step 5: Open a For-Next loop as shown below.

Code:

Sub VBA_Strconv4()

Dim Input1 As Long
Dim Output() As Byte

Output = StrConv("VBA String Conversion", vbFromUnicode)
For

Next

End Sub

Example 4.5

Step 6: In For loop, give value from 0 to UBound for Output variable under Input1.

Code:

Sub VBA_Strconv4()

Dim Input1 As Long
Dim Output() As Byte

Output = StrConv("VBA String Conversion", vbFromUnicode)

For Input1 = 0 To UBound(Output)

Next

End Sub

VBA Strconv Example 4.6

Step 7: At last, to print the values stored in Input1 through for loop we will use Debug.Print as shown below.

Code:

Sub VBA_Strconv4()

Dim Input1 As Long
Dim Output() As Byte

Output = StrConv("VBA String Conversion", vbFromUnicode)

For Input1 = 0 To UBound(Output)
Debug.Print Output(Input1)

Next

End Sub

Example 4.7

Step 8: Now run the code. We will see, in the immediate window, the sequence of Unicode will appear randomly.

VBA Strconv

Pros of VBA Strconv

  • Long set of data can easily be formatted with proper fonts with VBA Strconv.
  • For maintaining a database where we need to keep proper fonts which are mostly used, we can choose VBA Strconv to convert fonts in any format.

Things to Remember

  • It can only be used for texts.
  • This process is similar to the insert function of Excel where we can use Upper, Lower and Proper function to convert the fonts.
  • It can be automated by recording a macro. That will give the same results as VBA Strconv.
  • Save the file in Macro Enable Excel, so that you would be able to see and edit the code in the future.
  • We can use String or Long to define variables. Both can be used for text.

Recommended Articles

This is a guide to VBA StrConv. Here we discuss how to use Excel VBA StrConv Function along with practical examples and downloadable excel template. You can also go through our other suggested articles –

  1. VBA Copy Paste
  2. VBA RGB
  3. VBA Subscript out of Range
  4. VBA CDEC

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

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

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Web Development & many more.

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

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

EDUCBA

Download VBA Strconv Excel Template

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW