Although you can use the =PROPER () function or formula to capitalize all the words in a cell, there are times when you may want to capitalize the text in the same cell the data was entered, programmatically. Just follow these steps:
1. Hit [ALT]+[F11] to open the Visual Basic Editor
2. Hit [ALT]+[I]+[M], or just click “Insert” > “Module”
3. In the pop-up window copy the ff. code and edit the range “A1:A5”:
' Loop to cycle through each cell in the specified range.
For Each x In Range("A1:A5")
' There is not a Proper function in Visual Basic for Applications.
' So, you must use the worksheet function in the following form:
x.Value = Application.Proper(x.Value)
4. Hit [ALT]+[Q], or just click “File” > “Close and return to Microsoft Excel”
5. Run the Macro in Excel by going to:
Microsoft 2007: View > Macro > Macro and then Run “Proper_Case”
Microsoft 2010: Tools > Macros > View Macros and then Run “Proper_Case”.
This will capitalize all the text in the range you specified on the selected worksheet (cells A1:A5 in the example code above).
Want to lowercase text using an Excel macro? View this tutorial »
Want to uppercase text using an Excel macro? View this tutorial »