View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
JasonK[_3_] JasonK[_3_] is offline
external usenet poster
 
Posts: 38
Default last name first, first name last -- is there a code to combine 2 cells with last and first names?

Thank you Patrick. I will copy these and run them.

Thanks again for your help.

JasonK


On Fri, 17 Jul 2009 12:40:42 +0100, "Patrick Molloy"
wrote:

... so run CreateFullNames ONCE to merge B and C into B
then run SetCtoFirstName or SetCtoLastName ant anytime --- these just split
out the first or last name into C as you need

"Patrick Molloy" wrote in message
...
so B will be LstName, FirstName

Option Explicit

Sub CreateFullNames()
Dim source As Range
Set source = Range("B2")
Do Until source = ""
source.Value = source.Value & ", " & source.Offset(, 1).Value
Set source = source.Offset(1)
Loop
End Sub
Sub SetCtoFirstName()
Dim lastrow As Long
lastrow = Range("B2").End(xlDown).Row
Range(Range("C2"), Cells(lastrow, "C")).FormulaR1C1 = _
"=MID(RC2,FIND("","",RC2)+2,99)"
End Sub
Sub SetCtoLastName()
Dim lastrow As Long
lastrow = Range("B2").End(xlDown).Row
Range(Range("C2"), Cells(lastrow, "C")).FormulaR1C1 = _
"=LEFT(RC2,FIND("","",RC2)-1)"
End Sub





"JasonK" wrote in message
...
Thanks again for all your help. This group has been quite valuable to
me.

There are a couple of things I would like to do here.

First, I have two columns of data. Col B is last names, Col C is first
names. I would like to combine all that data into Col B with the Last
Name First, (comma space) then First Name.

Is there a quick macro I can write to do that?

Then, after the data is in that format, is there a way to reverse
column B so that the data is First Name First (space) Last Name (no
comma)?

That would be the best. I need the data both ways at different times
depending on what I'm doing.

Thanks again in advance for the advice.

JasonK