Split a textbox content into three separate textboxes

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I have a form on which I have first name, Middle name and last name.

Then I have one textbox labeled "full name" . Which takes the combination of the names in the three textboxes.

So now, I want to split those names from the full name textbox back into their original textboxes.

The only foreign characters will be a space , a hyphen or a dot

These are the conditions :
1. A name like "nice-name" should be treated as a single word.
2. A name like "nice name" should be treated as two words.
3. A name like "A. nice name" should be treated as three words.
4. If the number of words is only two, then place the first word into first name textbox and second word into last name textbox.
5. If more than two words, then place first word into first name textbox, place last word (first from right) into the last name textbox and the remaining words into the middle name textbox.


I have tried something but seems to take me somewhere else.
I was using this to split two words but the last line failed.

Code:
Private Sub d_Click ()
      a[COLOR=#333333]= Split (d.Text,  " ")(0)
[/COLOR]b[COLOR=#333333]= Split (d.Text,  " ")(1)[/COLOR][COLOR=#333333]
[/COLOR]End Sub

I know I am doing something wrongly however my skills are limited to fix it.

I needed some powerful brains fix it for me.

Thanks
 
Have you spotted that I replied to your post#6 question with enhanced code? (see post#7)

Yeah I have seen that.

That's where the error came from but I was able to fix it.

I am really grateful.
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,224,772
Messages
6,180,868
Members
453,003
Latest member
SalihZekiKoni

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