Macro for Title Case

rhmkrmi

Active Member
Joined
Aug 17, 2012
Messages
348
Office Version
  1. 365
Platform
  1. Windows
Hello,

Is there a macro that I can use to set the case for a range of cells to Title Case?

Thank you
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hello,

If you were to be more specific about the structure of your sheet ... a proposal could be drafted ... to produce your expected result ...
 
Upvote 0
Maybe something like
Code:
Sub rhmkrmi()
   With Selection
      .Value = Evaluate("if({1},proper(" & .Address & "),"""")")
   End With
End Sub
 
Upvote 0
Maybe something like
Code:
Sub rhmkrmi()
   With Selection
      .Value = Evaluate("if({1},proper(" & .Address & "),"""")")
   End With
End Sub

Should note that this only works if the selection consists of one area only, and any formulas will be converted to value.
 
Upvote 0
Thank you.

I am trying to make the case of cells A1:A10 tile case, for example, if the user types pRoject OF North West, or PROJECT of north west, the macro changes it to Project of North West.
 
Upvote 0
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
      Application.EnableEvents = False
      Target.Value = Application.Proper(Target.Value)
      Application.EnableEvents = True
   End If
End Sub
This needs to go in the relevant sheet module.
 
Upvote 0
Thanks a lot.
It works fine.
How can I make the range dynamic, like, A$1:A10?
Also, is there a way to make words like "of" and "the" always lower case in this macro?
 
Upvote 0
Simple answer no & no.
You can change the range the macro works on, but it cannot be changed dynamically.
To leave certain words lower case, you would need a list of all those words & then have to run comparisons, which is going to make things slow.
 
Upvote 0
Thanks a lot.
It works fine.
How can I make the range dynamic, like, A$1:A10?
Also, is there a way to make words like "of" and "the" always lower case in this macro?
I'll assume "dynamic" means whenever data is input to any cell in column A (if it means something else, post again).

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ray, i%
If Target.CountLarge > 1 Then Exit Sub
If Target.Column = 1 Then
    ray = Split(Application.Proper(Target), " ")
    For i = 1 To UBound(ray)
        If ray(i) = "Of" Or ray(i) = "The" Then ray(i) = LCase(ray(i))
    Next
    Application.EnableEvents = False
    Target = Join(ray, " ")
    Application.EnableEvents = True
End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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