Capitalizing but not McTavish or McDonald

# Thread: Capitalizing but not McTavish or McDonald

1. Senior Member
Join Date
Dec 1969
Posts
936

## Capitalizing but not McTavish or McDonald

How would I capitalize a surname but look out for McDonald:<BR><BR>McDonald --&#062; McDONALD<BR>Jones --&#062; JONES<BR>Smith --&#062; SMITH<BR>McTavish --&#062; McTAVISH<BR><BR>How would I write a funtion to do this?<BR>Thanks,<BR>Jamie

2. Senior Member
Join Date
Dec 1969
Posts
1,024

## RE: Capitalizing but not McTavish or McDonald

strSurname = "McDonald"<BR><BR>if left(strSurname, 2)="Mc" then<BR> strSurname = "Mc" & uCase(mid(strSurname, 3))<BR>else<BR> strSurname = uCase(strSurname)<BR>end if<BR><BR>something like that?? (obv, if you wanted to modify it to a function it wouldn&#039;t be difficult...)<BR><BR><BR><BR>cp

3. Senior Member
Join Date
Dec 1969
Posts
11,247

## RE: Capitalizing but not McTavish or McDonald

name = Ucase(name)<BR>If left(name, 2) = "MC" Then<BR> name = "Mc" & mid(name, 3)<BR>end if<BR><BR>Ok, so if you have MacKENZIE what do you do?<BR>

4. Senior Member
Join Date
Dec 1969
Posts
11,247

## Och Hoots Mon!

Interesting same approach different method !

5. Senior Member
Join Date
Dec 1969
Posts
2,049

Function properCase(str)<BR> str = Trim(str)<BR> str = Replace(str, " ", " ")<BR> str = Split(str," ")<BR> <BR> Dim x, tmp<BR> For Each x In str<BR> If Lcase(Left(x,2)) = "mc" And Len(x) &#062; 2 Then<BR> tmp = tmp &"Mc"& UCase( Mid(x,3,1) ) & LCase(Mid(x,4,Len(x)))<BR> Else<BR> tmp = tmp &" "& UCase( Mid(x,1,1) ) & LCase(Mid(x,2,Len(x)))<BR> End If<BR> Next<BR><BR> properCase = Trim(tmp)<BR>End Function<BR>

6. Senior Member
Join Date
Dec 1969
Posts
936

## There's a moose loose...

Thanks to you both.<BR><BR>Here&#039;s the function:<BR>&#039;Function to make LastName uppercase but looking out for McTavishes<BR>Function LastName(strName) <BR>strName = Ucase(strName) <BR>If left(strName, 2) = "MC" Then <BR> strName = "Mc" & mid(strName, 3) <BR>end if <BR>LastName = strName<BR>End Function

7. Senior Member
Join Date
Dec 1969
Posts
936

## ...aboot this hooose

Luckily there were no MacTavishes just McTavishes....

8. Senior Member
Join Date
Dec 1969
Posts
11,247