View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
JB JB is offline
external usenet poster
 
Posts: 115
Default How to sort a list with Mr, Mrs, Miss ?

With VBA:

http://cjoint.com/?dDtICJNMLz

Sub Sort()
Set First = Range("a1")
ncol = First.CurrentRegion.Columns.Count
nlig = First.CurrentRegion.Rows.Count - 1
First.Offset(0, ncol).EntireColumn.Insert Shift:=xlToRight
For Each c In First.Offset(1, 0).Resize(nlig, 1)
c.Offset(0, ncol) = WithOutCivil(c.Value)
Next c
First.CurrentRegion.Sort Key1:=First.Offset(1, ncol),
Order1:=xlAscending, Header:=xlGuess
First.Offset(0, ncol).EntireColumn.Delete
End Sub

Function WithOutCivil(chaine)
civilite = Array("Mr", "Miss", "Mrs")
WithOutCivil = chaine
p = InStr(chaine, " ")
If p < 0 Then
If Not IsError(Application.Match(UCase(Left(chaine, p - 1)),
civilite, 0)) Then
WithOutCivil = Mid(chaine, p + 1)
End If
End If
End Function

JB
http://boisgontierjacques.free.fr



On 27 mar, 17:48, Martin ©¿©¬ @nohere.net wrote:
Hi
I have a list of names in a spreadsheet that includes Titles, Names &
addresses

Name * * * * * *Address * * * * Town * *Postcode
Mr A Burns * * *24 Hill street * * * * *town * *postcode
Mrs B Mitchel * 45 Acreback road * * * *town * *postcode
Miss G Hay * * *The sheddings * * * * * town * *postcode
etc * * * * * * etc * * * * * * * * * * etc * * etc

How do I sort this list by surname?
It keeps sorting by Miss, Mr, Mrs
--
Martin
©¿©¬