Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
J Blumenthal
 
Posts: n/a
Default sorting columns with more than 2 text entries

DataText to ColumnsNext works well if all entries have a "single" first and
last name, eg, "Joe Smith". However, if there is a "Mary Joe Smith" listed,
how do I put only the last text entry into a new column? I am downloading
payment information from a PayPal account and want to sort by last name for
our lunches. Unfortunatley the "name" information (first, last, etc...) is
contained in a single cell.
--
JAB
  #2   Report Post  
Kevin Lehrbass
 
Posts: n/a
Default

Hi JAB!

Use this formula to extract the 1st name in cell A1: =LEFT(A1,FIND(" ",A1,1))
Use this formula to extract the last word (last name) in cell A1:
=RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1," ","*",LEN(A1)-LEN(SUBSTITUTE(A1,"
","")))))

Cheers,
--
Kevin Lehrbass
www.spreadsheetsolutions4u.com


"J Blumenthal" wrote:

DataText to ColumnsNext works well if all entries have a "single" first and
last name, eg, "Joe Smith". However, if there is a "Mary Joe Smith" listed,
how do I put only the last text entry into a new column? I am downloading
payment information from a PayPal account and want to sort by last name for
our lunches. Unfortunatley the "name" information (first, last, etc...) is
contained in a single cell.
--
JAB

  #3   Report Post  
Norman Jones
 
Posts: n/a
Default

Hi JAB,

Try:

Sub SplitNames2()
'////////////////////////////////////////////////////
'// Parse Nane string into constituent names
'// As written requires any name to be selected
'///////////////////////////////////////////////////

Dim FullNames As Range
Dim SplitNames As Range
Dim cel As Range
Dim FirstCel As Range
Dim LastCel As Range
Dim Surname As Range
Dim suffix As Variant
Dim i As Long
Dim j As Long

suffix = Array("PhD", "BSc", "MSc", "MA", "BA", _
"I", "II", "III", "IV",
"Jr")

Set FullNames = ActiveCell.CurrentRegion.Resize(, 1)

FullNames.TextToColumns Destination:=FullNames(1), _
DataType:=xlDelimited, _
TextQualifier:=xlNone, _
ConsecutiveDelimiter:=True, _
Tab:=False, _
Semicolon:=False, _
Comma:=True, _
Space:=True, _
Other:=False, _
FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1))

FullNames.Insert Shift:=xlToRight

Set SplitNames = FullNames.Offset(, 1).CurrentRegion

j = SplitNames.Columns.Count

For Each cel In FullNames
For i = LBound(suffix) To UBound(suffix)
Set LastCel = cel.End(xlToRight)
Set FirstCel = cel.Offset(, -1)

If UCase(LastCel.Value) = UCase(suffix(i)) Then
LastCel.Copy FirstCel
LastCel.ClearContents
Exit For
End If
Next
Set LastCel = cel.End(xlToRight)
Set Surname = cel.Offset(0, j - 1)

LastCel.Copy Surname
If Surname.Address < LastCel.Address Then
LastCel.ClearContents
End If
Next

If Application.WorksheetFunction. _
CountA(SplitNames.Columns(j)) 0 Then

If Application.WorksheetFunction. _
CountA(SplitNames.Columns(j - 1)) = 0 Then
SplitNames.Columns(j).Copy SplitNames.Columns(j - 1)
SplitNames.Columns(j).ClearContents
FullNames.Offset(, -1).Copy FullNames(1).Offset(, j - 1)
End If

End If

FullNames.Offset(, -1).Delete Shift:=xlToLeft

End Sub
'<<================================

Usage: Select any name in the list and run the above macro.

I regret that I am unable to ascribe credit for the macro as I no longer
have details of the author.

If you are not familiar with macros, you may wish to visit David McRitchie's
'Getting Started With Macros And User Defined Functions' at:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


---
Regards,
Norman



"J Blumenthal" wrote in message
...
DataText to ColumnsNext works well if all entries have a "single" first
and
last name, eg, "Joe Smith". However, if there is a "Mary Joe Smith"
listed,
how do I put only the last text entry into a new column? I am downloading
payment information from a PayPal account and want to sort by last name
for
our lunches. Unfortunatley the "name" information (first, last, etc...)
is
contained in a single cell.
--
JAB



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
Can I use Excel to match text data from 2 separate columns ? Dan Excel Worksheet Functions 1 September 29th 05 03:51 AM
Formulas dealing with text data Bagia Excel Worksheet Functions 6 June 20th 05 10:29 PM
Comparing text in columns Lear Excel Discussion (Misc queries) 1 June 8th 05 09:35 PM
How to keep rows together when sorting columns? Amit Excel Worksheet Functions 1 March 28th 05 06:01 PM
convert text labels to excel columns RSF New Users to Excel 2 February 9th 05 01:16 AM


All times are GMT +1. The time now is 07:27 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"