Elite Membership

VBA LCase

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 LCase Function

LCase is an inbuilt function in VBA used to convert an input string provided to it in the lowercase. It takes a single argument: the string is an input, and the output generated by this function is a string. The one thing to remember is that this function converts all the functions to lowercase, not just any single character.

Download FREE VBA LCase Excel Template and Follow Along!
Download Excel Template

You must have tried the same formula (LOWER) as Excel in VBA and have not found it. Because in VBA, the lowercase is slightly different. In VBA, it is a shortcut name, i.e., โ€œLCASE.โ€ Here โ€œLโ€ stands for โ€œLOWER,โ€ so the formula reads โ€œLOWERCASE.โ€

VBA LCase

Syntax

vba lowercase

Key Takeaways

  • String: is nothing but the text value we are trying to convert to lowercase. So we can supply the text directly to the formula, it can be a cell reference, and it can be through a variable.

How to Convert Text in Lowercase in VBA?

Example #1

Let us try converting the text value โ€œHello Good Morningโ€ to lower case using the LCASE function.

Step 1: Start the sub procedure by naming the excel macro.

Code:

Sub LCase_Example1()

End Sub
excel vba Lcase example 1.1

Step 2: Declare the variable k as String.

Code:

Sub LCase_Example1()

Dim k As String

End Sub
Lcase example 1.2

Step 3: Assign the value to the variable โ€œkโ€ by applying the โ€œLCASEโ€ function.

Lcase example 1.3

Step 4: Here, the string is our desired text value that we are trying to convert to lowercase, and the desired string value is โ€œHello Good Morning.โ€

Code:

Sub LCase_Example1()

Dim k As String

k = LCase("Hello Good Morning")

End Sub
Lcase example 1.4

Step 5: Now, show the variable โ€œkโ€ result in the message box.

Code:

Sub LCase_Example1()

Dim k As String

k = LCase("Hello Good Morning")

MsgBox k

End Sub
excel vba lcase example 1.5

Coding completed. Let us run the code to see the result.

excel vba lcase example 1.6

So LCase converted the text value โ€œHello Good Morningโ€ to โ€œhello good morningโ€ with the simple coding technique.

Example #2

We have seen how the LCASE function works in VBA. In the above example, we have directly supplied the value to the formula itself. Now, we will see how we can “use the cell reference value for the formula.

Assume you have the word โ€œHello Good Morningโ€ in cell A1 like the below image.

Lcase example 2.1

Step 1: We will convert the cell A1 value to the lower case by showing the result in the Range B1 cell so that the code will be Range (โ€œB1โ€).Value =

Code:

Sub LCase_Example2()

Range("B1").Value

End Sub
excel vba lcase example 2.2

Step 2: In cell B1, through the LCASE function, we will store the result, so open the function.

excel vba lcase example 2.3

Step 3: In this example, the VBA string value is a cell reference, not a direct value. So give the cell reference as Range (โ€œA1โ€).Value.

Code:

Sub LCase_Example2()

Range("B1").Value = LCase(Range("A1").Value)

End Sub
example 2.4

So, we have now completed the VBA coding part. Next, run the code and see the magic in the B1 cell.

example 2.5

Example #3

Converting a single cell value or a single direct value isnโ€™t the biggest challenge. However, when we deal with the โ€œnโ€ number of values in the worksheet, we need to apply loops to loop through all the cells and convert them to lower case values.

Assume below the data you have in an Excel worksheet.

example 3.1

If you are not aware of loops, then you need to go back to the basics of VBA coding. First, refer to our articles on โ€œVBA Loopsโ€ to have a fair bit of knowledge on loops. The below code will convert the above names to the lower case.

Code:

Sub LCase_Example3()

Dim k As Long

For k = 2 To 8
Cells(k, 2).Value = LCase(Cells(k, 1).Value)
Next k

End Sub
example 3.2

It will convert all the text values from row 2 to row 8 in the lowercase function.

example 3.3

Based on your cells, you can increase the limit of the loop from 8 to whatever the last row number of your data.

Recommended Articles

This article has been a guide to VBA LCase. Here, we discussed how to use the Excel VBA LCase function to convert the text into lowercase with the help of practical examples and a downloadable Excel template. Below are some useful articles related to VBA: –