Description:

We can automate task to Change Text Case – Upper Lower in Excel VBA. See the following examples to know how to do this.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

BROWSE ALL TEMPLATES

50+ Project Management Templates Pack
Excel PowerPoint Word

VIEW DETAILS

Advanced Project Plan & Portfolio Template
Excel Template

VIEW DETAILS

Ultimate Project Management Template
Excel Template

VIEW DETAILS

20+ Excel Project Management Pack
Excel Templates

VIEW DETAILS

20+ PowerPoint Project Management Pack
PowerPoint Templates

VIEW DETAILS

10+ MS Word Project Management Pack
Word Templates

VIEW DETAILS


Change Text Case – Upper Lower in Excel VBA: Solution

Change Text Case - Upper Lower in Excel VBA We can use UCase and LCase function to change a text into Upper and Lower.

Examples

Following are the examples to show you how to do this practically.

Sub sbChangeCASE()
      'Upper Case
      Range("A3") = UCase(Range("A3"))
      
      'Lower Case
      Range("A4") = LCase(Range("A4"))
End Sub
Instructions:

Follow the below instructions to do it yourself.

  1. Open an excel workbook
  2. Add some text at A3 and A4 ranges
  3. Press Alt+F11 to open VBA Editor
  4. Insert a Module for Insert Menu
  5. Copy the above code and Paste in the code window
  6. Save the file as macro enabled workbook
  7. Press F5 to execute it
Practical Applications:

Most of the times we use UCASE and LCASE function while comparing the text. For examples if we have two Columns and want to compare the Cells of each columns to check if they are same.

Let’s assume the following data is there in Column A and B, and we want to compare it and print it in Column C.

A B
Apples apples
Banana Bananaa
Red RED
GREEn Green
pink pink

If you write a procedure to compare this data without using UCASE or LCASE function, we may not get the desired results.

See the following Example code and output. We can observe that the its comparing but its case sensitive.

Sub sbCompareColumns_1()
iCntr = 1
Do While Cells(iCntr, 1) <> ""

If Cells(iCntr, 1) = Cells(iCntr, 2) Then
    Cells(iCntr, 3) = "Matched"
Else
    Cells(iCntr, 3) = "Not Matched"
End If

iCntr = iCntr + 1
Loop
End Sub

You can see the output in Column C:

Excel VBA Change Case upper lowers

I am using the same code with UCASE function, so that first it will convert to uppercase then compare it. We can avoid the case sensitivity.


Sub sbCompareColumns_2()
iCntr = 1
Do While Cells(iCntr, 1) <> ""

If UCase(Cells(iCntr, 1)) = UCase(Cells(iCntr, 2)) Then
    Cells(iCntr, 3) = "Matched"
Else
    Cells(iCntr, 3) = "Not Matched"
End If

iCntr = iCntr + 1
Loop
End Sub

You can see the output in Column C is different than the above result.

Excel VBA Change Case upper lower Example

LIMITED TIME OFFER - Get it Now!
Advanced Project Plan Excel Template

 
Related Resource External VBA Reference