Split First and Last name from ListBox into its respective cells

marimar02

Board Regular
Joined
May 21, 2010
Messages
118
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

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.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,286
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

marimar02

Board Regular
Joined
May 21, 2010
Messages
118
Office Version
  1. 365
Platform
  1. Windows
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...
 

Watch MrExcel Video

Forum statistics

Threads
1,130,059
Messages
5,639,807
Members
417,116
Latest member
Jakeyw

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
Top