MrExcel Message Board
enter>


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 30th, 2004, 03:38 PM   #1
Joey Jr
 
Join Date: Nov 2002
Posts: 19
Default From MCDONALD to Mcdonald to McDonald

Hi All,

I use the PROPER function to turn uppercase to sentence case when composing a mailing list.

Is there any way to capitalise the letter after the Mc or Mac at the start of certain surnames, without searching for 'Mc' and manually amending it?

Thanks
Joey Jr is offline   Reply With Quote
Old Mar 30th, 2004, 04:22 PM   #2
rrdonutz
 
Join Date: Jan 2003
Location: Round Rock, Texas
Posts: 564
Default Re: From MCDONALD to Mcdonald to McDonald

A related post that unfortunately doesn't really answer your question, except to point out the problem(s) with your request:

http://www.mrexcel.com/board2/viewtopic.php?t=70919

Maybe al_b_cnu's fuzzy lookup UDF can help, though?

BOL,

Tom
rrdonutz is offline   Reply With Quote
Old Mar 30th, 2004, 04:28 PM   #3
Joe4
MrExcel MVP
Moderator
 
Joe4's Avatar
 
Join Date: Aug 2002
Posts: 14,220
Default Re: From MCDONALD to Mcdonald to McDonald

You could write a macro to do the Search and Replace for you, but as the thread rrdonutz referenced suggests, there may be too many possibilites and exceptions to program something reliable.
__________________
TIPS FOR FINDING EXCEL SOLUTIONS
1. Use the built-in Help that comes with Excel/Access
2. Use the Search functionality on this board
3. A lot of VBA code can be acquired by using the Macro Recorder.
Joe4 is offline   Reply With Quote
Old Mar 30th, 2004, 04:33 PM   #4
DRJ
MrExcel MVP
 
DRJ's Avatar
 
Join Date: Feb 2002
Location: California
Posts: 3,857
Default

Try this:

=IF(LEFT(A1,2)="mc","Mc"&UPPER(MID(A1,3,1))&LOWER(MID(A1,4,LEN(A1))),IF(LEFT(A1,3)="mac","Mac"&UPPER(MID(A1,4,1))&LOWER(MID(A1,5,LEN(A1))),A1))
__________________
Excel VBA Training and Certification (Lesson 1 is free)
<hr>

<hr>-Jacob
DRJ is offline   Reply With Quote
Old Mar 30th, 2004, 05:08 PM   #5
rrdonutz
 
Join Date: Jan 2003
Location: Round Rock, Texas
Posts: 564
Default Re: From MCDONALD to Mcdonald to McDonald

Hi DRJ,

Your formula works, but . . . try it with names like:

Mack
Macklin
Mackovic

I doubt these folks want their names to become:

MacK
MacKlin
MacKovic

These are just a few of the exceptions that need a "work-around".
rrdonutz is offline   Reply With Quote
Old Mar 30th, 2004, 05:41 PM   #6
DRJ
MrExcel MVP
 
DRJ's Avatar
 
Join Date: Feb 2002
Location: California
Posts: 3,857
Default

Thats true. I suppose you could look at the letter after the mac or mc and if it is a D then capitalize it, or other letters that are likely to need to be capitals, but it is not 100%.

Of course the OP just wanted to cap the letter after mac or mc so that's all I tried to do.
__________________
Excel VBA Training and Certification (Lesson 1 is free)
<hr>

<hr>-Jacob
DRJ is offline   Reply With Quote
Old Mar 30th, 2004, 05:45 PM   #7
ultratch47
 
Join Date: Aug 2002
Location: Virginia
Posts: 126
Default Re: From MCDONALD to Mcdonald to McDonald

will you be using the same names every time?
If no new names are expected, then just program a macro around the names you have..
ultratch47 is offline   Reply With Quote
Old Mar 30th, 2004, 06:35 PM   #8
Ekim
 
Join Date: Jul 2002
Location: Perth, Australia
Posts: 1,416
Default Re: From MCDONALD to Mcdonald to McDonald

Joey,

One way:

Setup a matrix in the worksheet named “Setup":

******** ******************** ************************************************************************>
Microsoft Excel - Replace-Global Replace Words2.xls___Running: xl2002 XP : OS = Windows XP
(F)ile (E)dit (V)iew (I)nsert (O)ptions (T)ools (D)ata (W)indow (H)elp (A)bout
=

A
B
C
D
E
F
G
H
1
********
2
Incorrect*WordCorrect*Word******
3
MCDONALDMcDonald******
4
McdonaldMcDonald*The*cells*in*green*are*named*"myRng".*
5
********
6
********
7
********
8
********
9
********
10
********
11
********
Setup*

[HtmlMaker 2.42] To see the formula in the cells just click on the cells hyperlink or click the Name box
PLEASE DO NOT QUOTE THIS TABLE IMAGE ON SAME PAGE! OTHEWISE, ERROR OF JavaScript OCCUR.


The green cells are named “MyRng” – make it a dynamic range so that it auto corrects for additions/deletions.

Put the following macro in a normal module and assign it to a button from the Forms menu. The macro works on the Activesheet.

Code:
Option Explicit
Sub replaceWord()
Dim myReplace As Variant
Dim i As Integer

 With ThisWorkbook.Worksheets("Setup")
    myReplace = .Range("MyRng").Value
  End With

  For i = 1 To UBound(myReplace)
    If Not IsEmpty(myReplace(i, 1)) Then
      ActiveSheet.Cells.Replace What:=myReplace(i, 1), _
            Replacement:=myReplace(i, 2)
    End If
  Next i

End Sub
Another way is to update your autocorrect file so that the names change to the correct format as you input (assuming that you are manually entering the names).

HTH

Mike
Ekim is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 08:29 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.