VBA Upper, Lower, and Proper Case – Case Functions

Associated Files Download Links

While working in VBA, you often need to convert strings into lowercase, uppercase or proper case. This is possible by using the UCase, LCase and StrConv functions.

These functions are important when manipulating strings in VBA, as VBA is case sensitive. If you wish to make VBA case-insensitive, you need to add Option Compare Text at the top of your module. You can find out more about this here: Prevent VBA Case Sensitive

 

UCase – Convert String to Upper Case

The UCase function in VBA converts all letters of a string into uppercase. There is only one argument, which can be a string, variable with string or a cell value. This function is often used if you want to compare two strings. Here is the code for the UCase function:

In the example, we want to convert all letters of the strText variable to upper case and assign the converted string to the strTextUCase variable. At the end we call the message box with the converted string:vba-uppercase-function

Image 1. Using the UCase function in VBA

 

LCase – Convert String to Lower Case

If you want to convert all letters of a string into lower cases, you need to use the LCase function. This function has one argument, the same as the UCase. This is the code for the LCase function:

 

In this example, we convert all letters of the string from A1 into lower case. After that, the converted string is assigned to the cell A1.

vba-lowercase-function

Image 2. Using the LCase function in VBA

 

StrConv – Convert String to Proper Case

The StrConv function enables you to convert a string of text into proper case. The function has two arguments. First is the string that you want to convert. The second is the type of the conversion which you want. In order to convert a string to a proper case, you need to set it to vbProperCase. The code for the function is:

You will see on the example how the function works. It takes the string from the cell B1, converts it to proper case and returns the value in the cell A1.

vba-proper-case-function

Image 3. Using the StrConv function in VBA

 

StrConv – Convert String to Upper or Lower Case

Using the StrConv function, you can also convert a string to upper or lower cases. To do this, you just need to set the second argument to the vbUpperCase or vbLowerCase:

You may also like some of this related content...

VBA has many string functions that will allow you to manipulate and work with text
VBA Round The VBA Round Function rounds numbers to a specified number of digits. Syntax
Every character in Excel has an assigned number code to itself. The Chr function in
In this article, you will learn how to use the IsEmpty function in VBA to
Count Number of Words in a String The following VBA function counts the number of
Ads