Split First and Last name from ListBox into its respective cells

marimar02

Board Regular
Joined
May 21, 2010
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Hello,

what is the simplest way to split a (First and Last Name) value from UserForm ListBox when transferring to its respective cells (First Name column "D" and Last Name into column "E").

basically, my ListBox takes a list of Full Names from one range, I select that full name in ListBox and transfer to column "D", however with my current code, Full Name appears under First Name until I do another code to split it. I was hoping for simpler solution if it existed.

VBA Code:
Private Sub cmdAssign_Click()

'lstBox1 contains Full name that needs to be separated into selected cell as First Name and next to selected cell as Last Name'
Selection.Value = lstBox1.Value

Unload UF_Names

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Use split with space as delimiter to split out the first and last name, and resize the destination to 2 columns.
VBA Code:
Private Sub cmdAssign_Click()

    'lstBox1 contains Full name that needs to be separated into selected cell as First Name and next to selected cell as Last Name'
    Selection.Resize(, 2).Value = Split(lstBox1.Value, " ")

    Unload UF_Names

End Sub
 
Upvote 0
Solution
Use split with space as delimiter to split out the first and last name, and resize the destination to 2 columns.
VBA Code:
Private Sub cmdAssign_Click()

    'lstBox1 contains Full name that needs to be separated into selected cell as First Name and next to selected cell as Last Name'
    Selection.Resize(, 2).Value = Split(lstBox1.Value, " ")

    Unload UF_Names

End Sub
MAGIC. Thank you so much...
 
Upvote 0

Forum statistics

Threads
1,224,808
Messages
6,181,072
Members
453,020
Latest member
mattg2448

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