Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Reversing Names In Place.
by Allen Wyatt
(last updated July 5, 2017)
George often has to work with data provided by other people. In working with this data he may need to convert a name, say Joe Bloggs, so that the last name is first, as in Bloggs, Joe. George understands that he can use a formula to do the name reversal, but he needs to do it in the same cell in which the name resides. He wonders if there is a built-in command that will perform this task.
No, there isn't a built-in command to do it. You can, however, create a macro that will do the switching for you. This macro could then be assigned to a shortcut key or placed on a toolbar so it can be easily accessed. Here's a simple macro that will do the switching:
Sub ReverseNames() Dim x As Integer Dim sCell As String Dim sLast As String Dim sFirst As String Dim rCell As Range For Each rCell In Selection sCell = rCell.Value x = InStr(sCell, " ") If x > 0 Then sFirst = Left(sCell, x - 1) sLast = Mid(sCell, x + 1) rCell.Value = sLast & ", " & sFirst End If Next Set rCell = Nothing End Sub
To use the macro, just select the range of cells you want to affect and then run it. The macro searches for a space within the cell and considers everything in front of the space to be the first name and everything after the space to be the last name. These two elements are reversed, a comma put between them, and stuffed back into the cell.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3812) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Reversing Names In Place.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
If you have a macro that takes a long time to process a workbook, you might want to continue working in Excel while the macro ...Discover More
When processing a worksheet with a macro, it may be helpful to periodically recalculate the worksheet. Wouldn't it be nice if ...Discover More
Do you want to display a particular range of columns within the Excel window? Here's a couple ways you can accomplish the ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.