Text to columns to 3 columns

bobkap

Active Member
Joined
Nov 22, 2009
Messages
313
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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try something like:
VBA Code:
Dim aStr, carename as string

aStr=Split(carename,",")
Range("DestinationFirstNameCell")=aStr(0)
Range("DestinationLastNameCell")=aStr(ubound(aStr))
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,214,874
Messages
6,122,034
Members
449,061
Latest member
TheRealJoaquin

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