Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Capitalizing Just a Surname.

Capitalizing Just a Surname

by Allen Wyatt
(last updated June 16, 2017)

4

Cheryl is using a worksheet that has, in column A, client names in the format "Smith, Jane." She would like to capitalize only the surname, as in "SMITH, Jane", leaving the rest of the name unchanged.

If there is one and only one comma that separates the surname from the first name, you can create a formula to do the conversion. Assuming the name is in A1, the formula would be:

=UPPER(LEFT(A1,FIND(",",A1)-1))&MID(A1,FIND(",",A1),LEN(A1))

If you prefer to not use a formula (which may mess up the look of your worksheet), you could also use a macro to convert the names, in place. Consider the following:

Sub CapitalizeSurnames()
    Dim rCell As Range
    Dim iComma As Integer
    For Each rCell In Selection
        iComma = InStr(rCell, ",")
        If iComma > 0 Then
            rCell = UCase(Left(rCell, iComma - 1)) & _
              Mid(rCell, iComma)
        End If
    Next
    Set rCell = Nothing
End Sub

Simply select the cells that you want to convert (such as those in column A) and then run the macro. It makes the conversion to the names in the cells.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12639) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Capitalizing Just a Surname.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Better Use of Heading Space

If your column headings are too large to work well in your worksheet, why not turn them a bit? Here's how.

Discover More

Comparing Strings

As your macro is processing information, there will doubtless be times that it will need to compare information in ...

Discover More

Controlling the Bold Text Attribute

When processing a document in a macro, you may need to make some of your text bold. It's easy to do using the Bold ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Uncovering and Removing Links

Excel allows you to reference data in other workbooks by establishing links to that data. If you later want to get rid of ...

Discover More

How Many Rows and Columns Have I Selected?

Want a quick way to tell how may rows and columns you've selected? Here's what I do when I need to know that information.

Discover More

Getting Help when Entering Functions

Need a quick memory jog when entering a worksheet function? Here's a shortcut that will be invaluable.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is eight minus 1?

2017-06-18 13:22:53

Willy Vanhaelen

Here is a one line macro that does the job.

Sub CapitalizeSurnames()
Selection = Evaluate(Replace("IF(ISERROR(FIND("","",@)),@,UPPER(LEFT(@,FIND("","",@)-1))&MID(@,FIND("","",@),LEN(@)))", "@", Selection.Address))
End Sub


2017-06-17 06:27:49

John

Ah, good point.

I read it completely the wrong way and didn't test it either. Unforgiveable. :-)

Thanks for the correction - I'll be more careful when commenting (and reading!) in future.

John


2017-06-16 09:15:45

Bryan Marks

John, you raise a good point about the complexity involved with the capitalization of last names. However, the point of this tip is to capitalize the entire surname (e.g., "de la Croix" would become "DE LA CROIX", "Macdonald" would become "MACDONALD"). The code above does just that.


2017-06-16 05:18:34

John

This is far too simplistic - what about, say, 'de la Croix', or 'd'Oliviera', or 'Macdonald' and 'MacDonald'. It's pretty much impossible to cover every possibility, particularly as some surnames with exactly the same letters are capitalised differently depending on the person whose surname it is! I guess this is a reasonable approximation but definitely not a comprehensive solution.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.