unique ID from a name

User avatar
stuck
Panoramic Lounger
Posts: 8191
Joined: 25 Jan 2010, 09:09
Location: retirement

unique ID from a name

Post by stuck »

I would like a formula to convert a list of names in cells into a code number based on the first character of each part of the name and the number of characters in that part of the name, e.g.
Ann Other would become A3O5
Ann Other One would become A305O3
the word delimiter will always be a space but the name could have any number of parts, though I think a Spanish style in four parts (double Christian name, double surname) is likely to be the most complex.

I can get the first part with:
=CONCATENATE(LEFT(A1,1),(FIND(" ",A1)-1))
but already I'm thinking that's is probably not the way best way to start...

Ken

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: unique ID from a name

Post by HansV »

I think you'll need VBA for this. Copy the following function into a module:

Code: Select all

Function Name2Code(varName) As String
  Dim arrParts
  Dim i As Integer
  Application.Volatile
  arrParts = Split(varName)
  For i = LBound(arrParts) To UBound(arrParts)
    Name2Code = Name2Code & Left(arrParts(i), 1) & Len(arrParts(i))
  Next i
End Function
Use like this in a formula:

=Name2Code(A1)

If you store the function in your personal macro workbook Personal.xls (Excel 2003 or before) or Personal.xlsb (Excel 2007 or later), use

=Personal.xls!Name2Code(A1)

or

=Personal.xlsb!Name2Code(A1)

depending on your version of Excel.
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8191
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: unique ID from a name

Post by stuck »

That was quick and it does the job very nicely.
:chocciebar: :thankyou:

Ken

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15653
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: unique ID from a name

Post by ChrisGreaves »

stuck wrote:I would like a formula to convert a list of names in cells into a code number based on the first character of each part of the name and the number of characters in that part of the name,
The airline reservation systems have bene using this for 40+ years.
For the life of me I can't think of the name of the scheme; it'll come to me withing 30 minutes of hitting "Submit" and about three minutes after another lounger jogs my memory.
I know it was in full swing in 1973, for three of my team members were surprised at BOAC(?) offices in London by asking if their reservations were confirmed. "Name?"; "Witt", says one of the three, not spelling it out. "Witt, Malthus and Steketee confirmed" shot back the clerk in seconds, flooring all three of them.
He who plants a seed, plants life.

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: unique ID from a name

Post by HansV »

Do you mean Soundex?
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: unique ID from a name

Post by HansV »

stuck wrote:it does the job very nicely.
And it's a smart function too:
x53.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
Leif
Administrator
Posts: 7218
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: unique ID from a name

Post by Leif »

HansV wrote:And it's a smart function too:
Very clever!
Leif

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: unique ID from a name

Post by HansV »

Or for the Star Wars fans:
x54.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15653
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: unique ID from a name

Post by ChrisGreaves »

HansV wrote:Do you mean Soundex?
I knew it ...!
P.S. There's a FAQ in case you get the wrong name!
He who plants a seed, plants life.