How to Convert Small Letters into Uppercase Letters for few columns using VBA in Microsoft Excel
In this article we will learn how to convert text into capital letters in specific columns (not all cells) using VBA code.
Question): I want code that will replace the text enter in small letters into upper case in some columns (not all of them).
Say I do not want the code to run on columns 4, 6, 9, 12, & 13 i.e. if any text is entered in these columns then the code will not be triggered.
In order to get the upper case letters as you type in small letters; we need to follow the below steps to launch VB editor
- Click on Developer tab
- From Code group, select Visual Basic
Copy the following code in Sheet module
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 4 Or Target.Column = 6 Or Target.Column = 9 _
Or Target.Column = 12 Or Target.Column = 13 Then Exit Sub
On Error GoTo ErrHandler
Application.EnableEvents = False
Target.Formula = UCase(Target.Formula)
Application.EnableEvents = True
- The code will work in sheet1 only as the code is entered in sheet1
- The code will automatically replace the small letter typed by mistake or in ignorance immediately into upper case letter in all columns except 4, 6, 9, 12, & 13.
In this way, we can convert text to caps in specific columns using VBA code.