I have a list of several thousand items, which consist of several different names together like this:
Mr P Thompson & Mrs S Thompson & Mr A Thompson
Mr C Guy-Johnson & Mrs A Guye-Johnson & Miss J Guye-Johnson
Mrs Fuller & Ms D Fuller & Dr K U Fuller
Dr V Patel & Dr OO Patel
Mr B Burden & Mr MP Wood & Ms C Pollock
Mr PW Philips & Mrs PW Philips
Dr D Watson & S Holmes
Mr R Polanski & Mrs S Polanski
Mr S Spielberg & Miss G Spielberg & Mrs T Spielberg
Sometimes the surname is repeated within the cell, sometimes it is not.
I want to build a formula that will determine if the surname is repeated, and return a string where the Salutations/titles and inititals are concatenated with the Surname at the end, unless the surnames are different.
For example,
- Mr S Spielberg & Miss G Spielberg & Mrs T Spielberg
- Mr R Polanski & Mrs S Polanski
would become,
- Mr S & Miss G & Mrs T Spielberg
- Mr R & Mrs S Polanski
BUT:
- Mr B Burden & Mr MP Wood & Ms C Pollock
- Dr D Watson & S Holmes
would remain the same as the surnames are different
Is it possible to do that with formulas, (and not splitting the names using Text to Columns), and how would I do that please?
thanks Philip
I am sure Barry or Lori would come up with a smart formula :) However here is a VBA example which might just solve your boss's
breathing
problem ;)Paste this code in a module. (Tested only with the samples in the screenshot below). I took the liberty to manipulate one of the cell values to take into consideration multiple matches in surnames. See Cell
A1
Screenshot
In this task over the past week I found a use for this excellent formula by Mr Excel MVP Aladin Akyurek here which counts how many spaces are in a cell (used it to decide whether initials were needed as if no Salutaion or first name, only surname is used)
On Ozgrid Forums Jindon came up with this Regex solution which gives me yet more encouragement to hit my O'Reilly Regular Expressions Cookbook again:
and on VBA Express forums SNB came up with this lovely array CSE formula
also on VBA Express forums mdmackillop came up with this lovely bit of clever thinking:
which I modified and used as below:
also on Mr Excel Forums Gerald Higgins proposed this which I found quite entertaining trying to break down and decode:
(but I had already handed in my work to my manager so had already made use of Sid's solution)