Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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

Written by Allen Wyatt (last updated September 16, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021

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 are using Microsoft 365, you can use a more robust formula that checks to see if the name being evaluated includes a comma:

```=LET(x,FIND(",",A1),IF(IFERROR(x,0)>0,UPPER(LEFT(A1,x-1))&MID(A1,x,LEN(A1)),A1))
```

If it does not, then the original name, unchanged, is returned by the formula.

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.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12639) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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

Sending Drawing Objects to the Back or Front

Drawing objects can be placed in a document in such a way that they overlap with each other. If you want to arrange those ...

Discover More

Imagine how painful it would be if every time you started Excel it tried to load all the files in your root directory? ...

Discover More

Creating a Master Document Using Existing Subdocuments

If you decide to create a master document, it is easy to do by just adding one or more subdocuments to an existing ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

##### More ExcelTips (ribbon)

Sequentially Inputting Information

When entering data in a worksheet, you may only want to add information to the cells in a particular range. You can ...

Discover More

Converting Text to Values

When you import information originating in a different program, Excel may not do the best job at figuring out what ...

Discover More

Viewing the Contents of a Very Wide Cell on Demand

Each cell in a worksheet can hold quite a bit of information. If you want to see the information in the cell without the ...

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.

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}] (all 7 characters, in the sequence shown) 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 3 + 4?

2023-09-22 11:13:01

Willy Vanhaelen

@J. Woolley
Oops! I know that with the Worksheet_Change event Sub you often must disable events but as I made this UDF in a hurry, I forgot. :-( This is not an excuse because VBA doesn’t “forget” anything and I should not post a macro without thoroughly testing it.

For your remarks 2 and 3. You are of course right but one is not supposed to enter a formula in a column that must have only names in it. The purpose of the UDF is to enable you to enter new names in a list all lower case, one by one, transforming the surname automatically in upper case.

2023-09-20 15:39:13

J. Woolley

@Willy Vanhaelen
I posted a similar event procedure on the same day here: https://excelribbon.tips.net/T012550_Using_an_Input_Mask.html
Therefore, I noticed some issues with your procedure:
1. You need to disable events before changing Target; otherwise, the event procedure will repeat many times (46) for that Target.
2. If you enter a formula in column A that results in text with a comma, that formula will be replaced by a constant equal to the modified result.
3. If you copy N rows of names and paste them into column A, when the first name includes a comma it gets modified and duplicated in N rows of column A; otherwise, the N rows are pasted without change.
Here is an improved version of your procedure:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NameCells As Range, cell As Range, valu As String, iComma As Integer
Set NameCells = Range("A:A") 'adjust as requuired
For Each cell In Target
If Not (Application.Intersect(cell, NameCells) Is Nothing _
Or cell.HasFormula) Then
valu = cell.Value
iComma = InStr(valu, ",")
If iComma > 0 Then
valu = UCase(Left(valu, iComma - 1)) & Mid(valu, iComma)
Application.EnableEvents = False
cell.Value = valu 'low risk of error
Application.EnableEvents = True
End If
End If
Next cell
End Sub

2023-09-17 13:56:54

Willy Vanhaelen

Here is a macro that does the capitalization at the moment you enter the name (for column A):

Private Sub Worksheet_Change(ByVal Target As Range)
If Left(Target.Address, 3) <> "\$A\$" Then Exit Sub
Dim iComma As Integer
iComma = InStr(Target(1), ",")
If iComma = 0 Then Exit Sub
Target = UCase(Left(Target(1), iComma - 1)) & Mid(Target(1), iComma)
End Sub

Change "(\$A\$)" according to the column letter(s) you are using.

2023-09-16 10:09:49

J. Woolley

I believe the LET function is in Excel 2021 and later. Since Excel 365 is always later, I like to reference Excel 2021+ as shorthand when discussing such functions. And I encourage anyone how is serious about Excel to upgrade to Excel 2021+.

##### 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.