Make First Letter of Each Worh in a Cell to Upper Case

Denny57

Board Regular
Joined
Nov 23, 2015
Messages
185
Office Version
  1. 365
Platform
  1. Windows
I have successfully applied vba code to a text box in a User Form which will convert the first letter of each word to upper case using "vbProperCase".

Private Sub Textbox1_Change()
' Converts first letter of each work in the text to Upper case

With Me.ActiveControl
.Value = StrConv(.Value, vbProperCase)
End With

End Sub

I am looking to apply a Private Sub to a specific worksheet to convert all text input into 2 columns (B and J in rows 5 thru 70).

I have tried to adjust the above code however I keep getting error messages whatever change I make.

Any help would be appreciated
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How about:

VBA Code:
Sub CapitalizeFirstLetterOfWordsInSomeRanges()
'
    Range("B5:B70").Value = Application.Proper(Range("B5:B70").Value)
    Range("J5:J70").Value = Application.Proper(Range("J5:J70").Value)
End Sub
 
Upvote 0
I have copied the code to the appropriate worksheet as I have done for other worksheet specific code within a workbook but the first characters remain as lower case.

Macros are enabled and the file is saved as .xlsm
 
Upvote 0
It sounds like you want a worksheet event. See if this is the sort of thing you are after.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngProper As Range
    Dim rngUpdate As Range
    
    Application.EnableEvents = False

    Set rngProper = Range("B5:B70,J5:J70")
    Set rngUpdate = Intersect(Target, rngProper)

    If Not rngUpdate Is Nothing Then
        rngUpdate.Value = Application.Proper(rngUpdate.Value)
    End If

    Application.EnableEvents = True

End Sub
 
Upvote 0
I have copied the code to the appropriate worksheet as I have done for other worksheet specific code within a workbook but the first characters remain as lower case.

Macros are enabled and the file is saved as .xlsm

Sorry @Denny57, I didn't realize you wanted it to automatically run. The code I provided was designed to be run manually when you wanted it to run.
 
Upvote 0

Forum statistics

Threads
1,215,048
Messages
6,122,862
Members
449,097
Latest member
dbomb1414

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