StrConv VBA function – Text conversion

Last Updated on January 11, 2023 by token

1. StrConv VBA Function – Description

The StrConv VBA function  converts a text value by specified in the second argument of the parameter. With this function, you can, among other things, convert a string to uppercase like the VBA UCase function . We can convert the string to lowercase like the LCase VBA function . We can also return the result with a capital letter for the first character. The function can also be used to convert text to UniCode or convert text to UniCode .

2. VBA StrConv Function – Syntax

StrConv (String, Conversion As VbStrConv, [LocaleID As Long])

String : The string we want to convert.

Conversion : The type of conversion. We enter here a parameter from the table below, depending on what conversion we want to do:

Constant Value Description
vbUpperCase 1 Convert characters to uppercase.
vbLowerCase 2 Converts characters to lowercase.
vbProperCase 3 Capitalizes the first character of text.
vbUnicode 64 Converts the first character of text to UniCode.
vbFromUnicode 128 Converts a string from UniCode to the local code page.

LocaleID : Optional parameter. Specifies the local type of character encoding we want to use. If this argument is not completed, the parameter will be omitted.

Function return : String / Value text value.

3. VBA StrConv function – Example

How to use StrConv  function  in VBA Excel? Below are examples of using the StrConv function in the VisualBasic Editor.

Example 1 : An example of using the StrConv VBA function – result in the MsgBox window.

Dim StrValue As String
StrValue = "learning VBA functions"
MsgBox StrConv (StrValue, vbUpperCase)
MsgBox StrConv (StrValue, vbLowerCase)
MsgBox StrConv (StrValue, vbProperCase)
MsgBox StrConv (StrValue, vbUnicode)
MsgBox StrConv (StrValue, vbFromUnicode)

Example 2 : VBA StrConv – function example – result in an Excel sheet.

Dim StrValue2 As String
Range ("A1") = StrConv (StrValue, vbUpperCase)
Range ("A2") = StrConv (StrValue, vbLowerCase)
Range ("A3") = StrConv (StrValue, vbProperCase)
Range ("A4") = StrConv (StrValue, vbUnicode)
Range ("A5") = StrConv (StrValue, vbFromUnicode)
Excel VBA Functions - StrConv VBA function
Excel VBA Functions – StrConv VBA function

4. VB StrConv Feature – Additional information

  • In the second argument of the function, we can enter both a constant and a value that represents it.

5. StrConv VisualBasic function – Where to use?

The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016, Excel 2019, Excel 2021, Excel 365.

The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address:  VBA functions .

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: