Proper Case and Ordinal Numbers

JugglerJAF

Active Member
Joined
Feb 17, 2002
Messages
297
Office Version
  1. 365
Platform
  1. Windows
I have some basic code which converts data (address details) in a selected range to Proper Case, i.e. the first letter of each word is capitalised.

Code:
Sub Case_All_ProperCase()
For Each c In Selection
    c.Value = Application.Proper(c)
Next c
End Sub

Unfortunately, this also converts ordinal numbers such as 1st into 1St, 5th into 5Th and so on and converts anything following an apostrophe to a capital as well (e.g. "John's Court" becomes "John'S Court"

I can't simply do a find and replace on the St/Nd/Rd/Th elements of the text string as these may form part of a correctly capitalised address (e.g. I wouldn't want "High Street" to be changed back into "High street" or "The Boulevard" changed to "the Boulevard").

I had thought about replacing the specific ordinal number elements in their entirely(1St to 1st, 2Nd to 2nd and so on), but as this is address information, I could potentially have ANY number followed by the ordinal indicator, for example, my current data set has "50th Floor".

Is there any way of converting a range of text to Proper Case, but avoiding converting the text following a number or an apostrophe?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Maybe:

Code:
Sub Case_All_ProperCase()
Dim c As Range
For Each c In Selection
    c.Value = StrConv(c.Value, vbProperCase)
Next c
End Sub

Dom
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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