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: Reversing Names In Place.
by Allen Wyatt
(last updated October 3, 2015)
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 c As Range Dim n As Variant Dim s As String Dim j As Integer For Each c In Selection n = Split(c, " ") s = n(UBound(n)) & "," For j = LBound(n) To UBound(n) - 1 s = s & " " & n(j) Next j c.Value = Trim(s) Next c End Sub
To use the macro, just select the range of cells you want to affect and then run it. The macro separates the text in the cell into individual words (as separated by spaces) and then builds the name back again. It will handle two-word names (such as Joe Bloggs) just fine, but it will also handle longer names (such as Joseph Andrew Bloggs) just as easily.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11399) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Reversing Names In Place.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Need to hide some macros in your workbook? There are three ways you can do it, as covered in this discussion.Discover More
You may need to automatically generate unique numbers when you create new worksheets in a workbook. Here are a couple of easy ...Discover More
Need to know how many characters there are in a workbook? You can find out easily with the handy macro introduced in this ...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 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.