Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365. 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.
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:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12639) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Capitalizing Just a Surname.
Program Successfully in Excel! This guide will provide you with all the information you need to automate any task in Excel and save time and effort. Learn how to extend Excel's functionality with VBA to create solutions not possible with the standard features. Includes latest information for Excel 2024 and Microsoft 365. Check out Mastering Excel VBA Programming today!
If you distribute a workbook that is used by others for data entry, you may want a way to make sure they fill in certain ...
Discover MoreWhat do you do if a keypress you know worked correctly before all of a sudden stops working as you expect? This tip ...
Discover MoreIf you have some numbers stored in cells that are formatted as text, you may get some surprises when you try to use those ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2023-09-22 11:13:01
Willy Vanhaelen
@J. WoolleynOops! 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.nnFor 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 VanhaelennI posted a similar event procedure on the same day here: https://excelribbon.tips.net/T012550_Using_an_Input_Mask.htmlnTherefore, I noticed some issues with your procedure:n1. You need to disable events before changing Target; otherwise, the event procedure will repeat many times (46) for that Target.n2. 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.n3. 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.nHere is an improved version of your procedure:nnPrivate Sub Worksheet_Change(ByVal Target As Range)n Dim NameCells As Range, cell As Range, valu As String, iComma As Integern Set NameCells = Range("A:A") 'adjust as requuiredn For Each cell In Targetn If Not (Application.Intersect(cell, NameCells) Is Nothing _n Or cell.HasFormula) Thenn valu = cell.Valuen iComma = InStr(valu, ",")n If iComma > 0 Thenn valu = UCase(Left(valu, iComma - 1)) & Mid(valu, iComma)n Application.EnableEvents = Falsen cell.Value = valu 'low risk of errorn Application.EnableEvents = Truen End Ifn End Ifn Next cellnEnd 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):nnPrivate Sub Worksheet_Change(ByVal Target As Range)nIf Left(Target.Address, 3) <> "$A$" Then Exit SubnDim iComma As IntegerniComma = InStr(Target(1), ",")nIf iComma = 0 Then Exit SubnTarget = UCase(Left(Target(1), iComma - 1)) & Mid(Target(1), iComma)nEnd SubnnChange "($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+.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2026 Sharon Parq Associates, Inc.
Comments