VBA to Split Name When the Name is the Output From VLOOKUP

DavidWF

Board Regular
Joined
Oct 14, 2015
Messages
130
I use VLOOKUP to bring a person's name from a database into a form. In the database the name always has the format of christian name(s) followed by surname. There can be 1, or 2, or however many christian names.

The form requires that I enter surname in one cell and christian name(s) in a separate cell so I need to split the name.

The problem that I'm having, when I try the various methods that have previously been posted for splitting names, is that the underlying VLOOKUP formula gets split, not the visible output from the formula.

How do I resolve this so that the visible name gets split, not the underlying formula? At the moment I'm bringing the full name into cell AJ3; the surname has to be put into cell F37 and the christian name(s) into S37. If it helps, there's plenty of spare real estate to the right of the form, so if a helper cell is needed for temporary data, any cell (other than AJ3) to the right of col AH and between rows 1 to 50, is available. I'll assign the coding to a "Split Names" button on the worksheet.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Code:
[COLOR=darkblue]Sub[/COLOR] Split_Names()
    Range("F37").Value = Split(Range("AJ3").Value)(1)
    Range("S37").Value = Split(Range("AJ3").Value)(0)
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

You could do it with formulas instead...
F37
=TRIM(MID(SUBSTITUTE(AJ3," ",REPT(" ",99)),99,99))

S37
=LEFT(AJ3,SEARCH(" ",AJ3)-1)
 
Last edited:
Upvote 0
Thanks AlphaFrog

I've not tried the VBA but the formula solution worked well provided there was only 1 christian name. When there were 2 christian names the formula split the two christian names and ignored the surname.
 
Upvote 0
Just tried the VBA and it too does the same thing. I need the ability to separate the surname from the 1, or 2, or however many christian names there may be.

Thanks.
 
Upvote 0
How about
in F37
=TRIM(RIGHT(SUBSTITUTE(AJ3," ",REPT(" ",100)),100))
and in S37
=TRIM(SUBSTITUTE(AJ3,F37,""))
 
Upvote 0
Names are tricky. What if you have a 2 or more word surname; Van Patten, Della Rossa, Van der Hutten?
 
Upvote 0
Thanks Fluff.

We're halfway there - the F37 formula works perfectly.

The S37 formula returns:
For 1 christian name: F37 = christian name + surname
For 2 christian names: F37 = 2 christian names + surname
For 3 christian names: F37 = 1st and 3rd christian names + surname

Yes AlphaFrog, you're absolutely correct, names are indeed tricky and the examples you gave show this. I've scrolled back through about 5 years of the database and the occurrences of multi-name surnames are infrequent, so I'm quite happy if the formula assumes that the surname is a single word and I'll figure out a work-around for the times when the surname is multi-name. Maybe I'll need to create a Reset button that reinstates the formula in each cell if either has to be over-written because of an uncommon name structure. Just need to get the formula right first though.
 
Upvote 0
Surname F37
=TRIM(RIGHT(SUBSTITUTE(AJ3," ",REPT(" ",100)),100))

S37
=LEFT(AJ3,LEN(AJ3)-LEN(F37)-1)
 
Last edited:
Upvote 0
Thanks AlphaFrog, we're almost there. The S37 formula is correctly splitting out the christian name(s) but in all cases it's also adding the first letter of the surname.
 
Upvote 0

Forum statistics

Threads
1,215,431
Messages
6,124,855
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top