Using Excel VBA to Capitalize the First Letter of Each Word – 3 Examples

The dataset contains employee names and their designation.

To capitalize the first letter of each word:

3 Ideal Examples of Excel VBA to Capitalize First Letter of Each Word


Example 1 – Using the VBA Proper Function to Capitalize the First Letter of Each Word

STEPS:

  • Go to Developer.
  • Select Visual Basic to open the Visual Basic Editor. You may also press Alt + F11

3 Ideal Examples of Excel VBA to Capitalize First Letter of Each Word

  • or right-click the sheet and select View Code.

  • Select Module in Insert.

3 Ideal Examples of Excel VBA to Capitalize First Letter of Each Word

 

  • Enter the following VBA code.

VBA Code:

Sub CapitalizeEachWord()
    Set rng = Application.Selection
    Set rng = Application.InputBox("Select Range", "CapitalizeFirstWord", rng.Address, Type:=8)
    For Each myCell In rng
       myCell.Value = Application.Proper(myCell.Value)
    Next
End Sub
  • To save the code in your workbook, click save or press Ctrl + S. Make sure you save it as a Macro enabled .xlsm file.

  • Go back to the worksheet and go to the Developer tab.
  • To run the macros click Macros in Code.

3 Ideal Examples of Excel VBA to Capitalize First Letter of Each Word

  • In the Macro window, click Run.

  • Select the range of cells you want to capitalize the first letter of each word. Here, $B$5:$C$10.
  • Click OK.

This is the output.

Read More: How to Change Lowercase to Uppercase in Excel


Example 2 – Using the StrConv Function to Capitalize the First Letter of Each Word in Excel VBA

STEPS:

  • Go to the Developer tab.
  • Click Visual Basic to open the Visual Basic Editor or press Alt + F11. You cal also right-click the sheet and select View Code.
  • Go to Insert and select Module.
  • In the visual basic window, enter the VBA code below.

VBA Code:

Sub CapitalizeFirstWord1()
  Dim rng As Range
  For Each rng In Range("G5:G10")
    rng.Value = StrConv(rng.Value, vbProperCase)
  Next rng
End Sub
  • Press F5 key or click Run Sub to run the code.

 

  • This will capitalize the first letter of each word.

Read More: How to Make First Letter of Sentence Capital in Excel


Example 3 – Capitalize the First Letter of Each Word with the VBA UCase Function

STEPS:

  • Select B5:C10.

  • Go to the Developer tab.
  • Click Visual Basic to open the Visual Basic Editor or press Alt + F11. You cal also right-click the sheet and select View Code.
  • Go to Insert and select Module.
  • In the visual basic window, enter the VBA code below.

VBA Code:

Sub CaptalizeFirstWord2()
For Each cell In Selection.Cells
  wrd = Split(cell.Value)
  For i = LBound(wrd) To UBound(wrd)
    wrd(i) = UCase(Left(wrd(i), 1)) & Mid(wrd(i), 2)
  Next i
  cell.Value = Join(wrd)
Next cell
End Sub
  • Press F5 key or click Run Sub to run the code.

 

  • This will capitalize the first letter of each word.


Things to Keep in Mind

  • Enable the Developer tab: Choose File > Options, and Customize Ribbon. Check Developer.

Download Practice Workbook

Download the workbook and practice.


Related Articles


<< Go Back to Change Case | Text Formatting | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Sabrina Ayon
Sabrina Ayon

Sabrina Ayon, a Computer Science and Engineering graduate from United International University, has been an integral part of the ExcelDemy project for two years. She authored 150+ articles, excelling in instructing through visually engaging Excel tutorials. With a passion for teaching, Sabrina conducted sessions on Excel VBA, sharing her knowledge and insights with others. Currently holding the position of Project Manager for the ExcelDemy Visual Development Project, she oversees various aspects of the project, ensuring its smooth operation... Read Full Bio

2 Comments
  1. Excellent, well done.

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo