ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change order of data in a cell (https://www.excelbanter.com/excel-programming/422050-re-change-order-data-cell.html)

Ron Rosenfeld

Change order of data in a cell
 

On Tue, 6 Jan 2009 13:06:06 -0800, David
wrote:

Is it possible to write a macro that will change cells that have "Last Name,
First Name, Middle Initial" to "First Name, Middle Initial, Last Name" ?
Thank you for your help.
David


Yes it is.

Are you certain the data format is exactly as you have provided?
i.e. All cells have exactly three segments separated by commas.

Are you certain you want to have commas separating the segments in the result?

At its simplest, you could use something like:

==============
Option Explicit
Sub FixName()
Dim c As Range
Dim s
For Each c In Selection
s = Split(c.Text, ",")
c.Value = s(1) & ", " & s(2) & ", " & s(0)
Next c
End Sub
==================

Of course, since your original and result formats are identical, you'd have to
set up a routine to ensure that you didn't run the macro twice on the same
cell.
--ron


All times are GMT +1. The time now is 08:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com