Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Switch names in cell

Does anyone have a routine that can take a list of names entered as
"Lastname, Firstname" and change those names to "Firstname Lastname" within
the same cells?

Thanks,

--
tj
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Switch names in cell

How robust does it need to be

Dim cell as Range, sStr as String
for each cell in Selection
v = Application.Split(cell,",")
sStr = Trim( trim(v(Ubound(v))) & " " & trim(v(Lbound(v))))
cell.Value = sStr
Next

--
Regards,
Tom Ogilvy

"tjtjjtjt" wrote in message
...
Does anyone have a routine that can take a list of names entered as
"Lastname, Firstname" and change those names to "Firstname Lastname"

within
the same cells?

Thanks,

--
tj



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Switch names in cell

Take a look at
http://www.vbaexpress.com/forum/show...hlight=brettdj



--
HTH

Bob Phillips

"tjtjjtjt" wrote in message
...
Does anyone have a routine that can take a list of names entered as
"Lastname, Firstname" and change those names to "Firstname Lastname"

within
the same cells?

Thanks,

--
tj



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Switch names in cell

Try the following:

Dim Rng As Range
Dim S As String
Dim Pos As Integer
For Each Rng In Range("A1:A10")
S = Rng.Text
Pos = InStr(1, S, ",")
If Pos 0 Then
Rng.Value = Mid(S, Pos + 2) & " " & Left(S, Pos - 1)
End If
Next Rng




--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"tjtjjtjt" wrote in message
...
Does anyone have a routine that can take a list of names
entered as
"Lastname, Firstname" and change those names to "Firstname
Lastname" within
the same cells?

Thanks,

--
tj



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Switch names in cell

I got a run time error (438: Object doesn't support this property of method)
on the line Application.Split.

I'll ultimately want to be able to identify the column of names within a
list of information and then switch the names.
The names are usually, but not always, in Column A, so the code will need to
look for one of two words, "Name" or "Instructor," and then switch the names
in every record.

--
tj


"Tom Ogilvy" wrote:

How robust does it need to be

Dim cell as Range, sStr as String
for each cell in Selection
v = Application.Split(cell,",")
sStr = Trim( trim(v(Ubound(v))) & " " & trim(v(Lbound(v))))
cell.Value = sStr
Next

--
Regards,
Tom Ogilvy

"tjtjjtjt" wrote in message
...
Does anyone have a routine that can take a list of names entered as
"Lastname, Firstname" and change those names to "Firstname Lastname"

within
the same cells?

Thanks,

--
tj






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Switch names in cell

For the OP.
Lastname, firstname is already delimited by the comma, so the machinations
of the link are unnecessary. No mention was made of middle names or such.

--
Regards,
Tom Ogilvy



"Bob Phillips" wrote in message
...
Take a look at
http://www.vbaexpress.com/forum/show...hlight=brettdj



--
HTH

Bob Phillips

"tjtjjtjt" wrote in message
...
Does anyone have a routine that can take a list of names entered as
"Lastname, Firstname" and change those names to "Firstname Lastname"

within
the same cells?

Thanks,

--
tj





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Switch names in cell

My typo. Application.split should just be Split.

This worked fine for me (xl2003)

Sub abc()
Dim cell As Range, sStr As String
For Each cell In Selection
v = Split(cell, ",")
sStr = Trim(Trim(v(UBound(v))) & " " & Trim(v(LBound(v))))
cell.Value = sStr
Next

End Sub


Note that split is not provided in xl97 and earlier.

--
Regards,
Tom Ogilvy

"tjtjjtjt" wrote in message
...
I got a run time error (438: Object doesn't support this property of

method)
on the line Application.Split.

I'll ultimately want to be able to identify the column of names within a
list of information and then switch the names.
The names are usually, but not always, in Column A, so the code will need

to
look for one of two words, "Name" or "Instructor," and then switch the

names
in every record.

--
tj


"Tom Ogilvy" wrote:

How robust does it need to be

Dim cell as Range, sStr as String
for each cell in Selection
v = Application.Split(cell,",")
sStr = Trim( trim(v(Ubound(v))) & " " & trim(v(Lbound(v))))
cell.Value = sStr
Next

--
Regards,
Tom Ogilvy

"tjtjjtjt" wrote in message
...
Does anyone have a routine that can take a list of names entered as
"Lastname, Firstname" and change those names to "Firstname Lastname"

within
the same cells?

Thanks,

--
tj






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Switch names in cell

That did it. Thanks.
--
tj


"Tom Ogilvy" wrote:

My typo. Application.split should just be Split.

This worked fine for me (xl2003)

Sub abc()
Dim cell As Range, sStr As String
For Each cell In Selection
v = Split(cell, ",")
sStr = Trim(Trim(v(UBound(v))) & " " & Trim(v(LBound(v))))
cell.Value = sStr
Next

End Sub


Note that split is not provided in xl97 and earlier.

--
Regards,
Tom Ogilvy

"tjtjjtjt" wrote in message
...
I got a run time error (438: Object doesn't support this property of

method)
on the line Application.Split.

I'll ultimately want to be able to identify the column of names within a
list of information and then switch the names.
The names are usually, but not always, in Column A, so the code will need

to
look for one of two words, "Name" or "Instructor," and then switch the

names
in every record.

--
tj


"Tom Ogilvy" wrote:

How robust does it need to be

Dim cell as Range, sStr as String
for each cell in Selection
v = Application.Split(cell,",")
sStr = Trim( trim(v(Ubound(v))) & " " & trim(v(Lbound(v))))
cell.Value = sStr
Next

--
Regards,
Tom Ogilvy

"tjtjjtjt" wrote in message
...
Does anyone have a routine that can take a list of names entered as
"Lastname, Firstname" and change those names to "Firstname Lastname"
within
the same cells?

Thanks,

--
tj






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Switch names in cell

Thanks, Chip.
--
tj


"Chip Pearson" wrote:

Try the following:

Dim Rng As Range
Dim S As String
Dim Pos As Integer
For Each Rng In Range("A1:A10")
S = Rng.Text
Pos = InStr(1, S, ",")
If Pos 0 Then
Rng.Value = Mid(S, Pos + 2) & " " & Left(S, Pos - 1)
End If
Next Rng




--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"tjtjjtjt" wrote in message
...
Does anyone have a routine that can take a list of names
entered as
"Lastname, Firstname" and change those names to "Firstname
Lastname" within
the same cells?

Thanks,

--
tj




  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Switch names in cell

Thanks, Bob. Always nice to see different ways to do things.
--
tj


"Bob Phillips" wrote:

Take a look at
http://www.vbaexpress.com/forum/show...hlight=brettdj



--
HTH

Bob Phillips

"tjtjjtjt" wrote in message
...
Does anyone have a routine that can take a list of names entered as
"Lastname, Firstname" and change those names to "Firstname Lastname"

within
the same cells?

Thanks,

--
tj




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Switch First and Last Names Karen Excel Worksheet Functions 3 February 4th 10 07:40 PM
Switch names kathy at the front desk Excel Worksheet Functions 7 November 24th 09 08:46 PM
how do i switch the first and last name in a cell? Slac Excel Discussion (Misc queries) 3 June 17th 08 09:00 PM
How do I switch the names in a column in Excel Help Me - I need to switch these names Excel Worksheet Functions 2 January 20th 06 07:20 PM
How do I switch names around in excel? Erin Excel Worksheet Functions 2 April 8th 05 05:09 PM


All times are GMT +1. The time now is 06:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"