VBA To Capitalize First Letter Of Every Word In Cell

data808

Active Member
Joined
Dec 3, 2010
Messages
353
Office Version
  1. 2019
Platform
  1. Windows
I would like to be able to type into columns D and E and have the first letter for each word be capitalized for every cell.

Does anyone have the VBA code to do this?

Thank you for your help on this.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Please try the following worksheet change code for the sheet in question. Right-click the sheet tab, select View Code & paste the code into the window that appears on the right of screen.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("D:E"), Target) Is Nothing Then
        On Error GoTo Escape
        Application.EnableEvents = False
        Target.Value = WorksheetFunction.Proper(Target.Value)
    End If
Continue:
    Application.EnableEvents = True
    Exit Sub
Escape:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume Continue
End Sub
 
Upvote 1
Solution
Maybe this way
VBA Code:
Sub MM1()
Dim rng As Range, lr As Long
lr = Cells(Rows.Count, "D").End(xlUp).Row
For Each rng In Range("D2:E" & lr)
rng.Value = StrConv(rng.Value, vbProperCase)
Next rng
End Sub
 
Upvote 0
Please try the following worksheet change code for the sheet in question. Right-click the sheet tab, select View Code & paste the code into the window that appears on the right of screen.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("D:E"), Target) Is Nothing Then
        On Error GoTo Escape
        Application.EnableEvents = False
        Target.Value = WorksheetFunction.Proper(Target.Value)
    End If
Continue:
    Application.EnableEvents = True
    Exit Sub
Escape:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume Continue
End Sub
Thank you very much. This is working great!
 
Upvote 0
Maybe this way
VBA Code:
Sub MM1()
Dim rng As Range, lr As Long
lr = Cells(Rows.Count, "D").End(xlUp).Row
For Each rng In Range("D2:E" & lr)
rng.Value = StrConv(rng.Value, vbProperCase)
Next rng
End Sub
Thank you for the attempt. Couldn't get this one to work.
 
Upvote 0
Maybe this way
VBA Code:
Sub MM1()
Dim rng As Range, lr As Long
lr = Cells(Rows.Count, "D").End(xlUp).Row
For Each rng In Range("D2:E" & lr)
rng.Value = StrConv(rng.Value, vbProperCase)
Next rng
End Sub
The StrConv version of making a text string proper case is not as good as calling Excel's PROPER function through the Worksheefunction object (as kevin9999 did). Try both on the following text string to see the difference...
"one-two(three)"
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,122,998
Members
449,092
Latest member
masterms

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top