ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Proper case using VBA (https://www.excelbanter.com/excel-programming/389103-proper-case-using-vba.html)

Jock

Proper case using VBA
 
How can I force 'proper' case for text within excel
The following code forces uppercase, however I would like only the first
letters of each word capitalized: ie Joe Bloggs.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("E3:F200")) Is Nothing Then
Target(1).Value = UCase(Target(1).Value)
End If
Application.EnableEvents = True
End Sub

Can this be tweaked to what I woulf like?
--
tia

Jock

Mike H

Proper case using VBA
 
This may work:-
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count 1 Or Target.HasFormula Then Exit Sub
Application.EnableEvents = False
Target = StrConv(Target, vbProperCase)
Application.EnableEvents = True

End Sub

Mike

"Jock" wrote:

How can I force 'proper' case for text within excel
The following code forces uppercase, however I would like only the first
letters of each word capitalized: ie Joe Bloggs.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("E3:F200")) Is Nothing Then
Target(1).Value = UCase(Target(1).Value)
End If
Application.EnableEvents = True
End Sub

Can this be tweaked to what I woulf like?
--
tia

Jock



All times are GMT +1. The time now is 05:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com