
Here's a VBA code snippet that will convert the text in the selected cells to Proper Case (where the first letter of each word is capitalized):
Sub ConvertToProperCase()
Dim rng As Range
Dim cell As Range
' Set the range to the selected cells
Set rng = Selection
' Loop through each cell in the selected range
For Each cell in rng
' Check if the cell contains text
If Not IsEmpty(cell.Value) Then
cell.Value = Application.WorksheetFunction.Proper(cell.Value)
End If
Next cell
End Sub
How to Use This Code:
- Press ALT + F11 to open the VBA editor.
- Go to Insert > Module to insert a new module.
- Copy and paste the code into the module.
- Close the VBA editor.
- Select the cells you want to convert to Proper Case.
- Press ALT + F8, select ConvertToProperCase, and click Run.
This will change the text in the selected cells to Proper Case.
Tags:
VBA Codes