PDA

View Full Version : How to change mixed case names to proper case?



ianma81
06-07-2008, 04:52 AM
Hi guys,

Am trying to run a marco so i can input data into A1 and C2 will it sort out into proper case

For example JOhn Mcdonald

the code sorts it out to look like this John McDonald

Or PHil Odonnell

Should look like Phil O'Donnell

Am also looking for the code that will pick up post code for example pa3 3xr will look like PA3 3XR

Thanks in advance

Bob Phillips
06-07-2008, 05:19 AM
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1,C2" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target

.Value = Application.Proper(.Value)
.Value = Replace(.Value, " Mcd", " McD")
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.

mdmackillop
06-07-2008, 05:29 AM
There is no general rule that you can apply to Mc, Mac etc.
MacDonald
Macdonald
McDonald
Mcdonald
are all valid.

Aussiebear
06-07-2008, 06:24 AM
So to is;
Mackillop
Mckillop

:devil2:

mdmackillop
06-07-2008, 06:32 AM
But some are more valid that others. :thumb
MD MacKillop