Text to columns to 3 columns

bobkap

Board Regular
Joined
Nov 22, 2009
Messages
241
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I have a list of names where both first and last name is separated by a comma. I need to have the last name in one column and the first in another. I think I've figured out how to do that with this code below. Except I cannot figure out how to address two things.
1. If the person's first name is two words (ex.: Billy Joe; or Bobby Sue etc) I end up with 3 columns, not 2. I thought the "consecutive delimeter" would address that but it does not. Might anyone know how to handle that please?
2. Smith, Mary keeps the comma such as "Smith," in the column for the last name. Is there some easy way I can get rid of that comma?

Range(Cells(1, carename), Cells(finalrow, carename)).TextToColumns Destination:=Range("a1"), consecutivedelimiter:=True, DataType:=xlDelimited, Space:=True

Any help would be greatly appreciated!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

eduzs

Well-known Member
Joined
Jul 6, 2014
Messages
695
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Try something like:
VBA Code:
Dim aStr, carename as string

aStr=Split(carename,",")
Range("DestinationFirstNameCell")=aStr(0)
Range("DestinationLastNameCell")=aStr(ubound(aStr))
 

bobkap

Board Regular
Joined
Nov 22, 2009
Messages
241
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Try something like:
VBA Code:
Dim aStr, carename as string

aStr=Split(carename,",")
Range("DestinationFirstNameCell")=aStr(0)
Range("DestinationLastNameCell")=aStr(ubound(aStr))
Thanks very much!
 

eduzs

Well-known Member
Joined
Jul 6, 2014
Messages
695
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
You're welcome.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,790
Messages
5,638,326
Members
417,021
Latest member
moon miner

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