Text To Columns Question

bh24524

Active Member
Joined
Dec 11, 2008
Messages
365
Office Version
  1. 365
  2. 2007
I am about to set up a macro for a report I need to download weekly that has employee address information in order to stay current on their addresses for a mail merge I use weekly. Basically there are unneeded columns and then sorting that needs done. Unfortunately, the report comes with their First and last name in the same column and it is put as first name first. I have to use the text to columns feature to separate their first and last name at each occurrence of a "space" Here is the problem: Some people might have a name with a space like "Mary Ann" or "Mary Jane". Another person has a last name with spaces like "Van Atta" and other might have Jr or Sr afgter their last name. The issue with that is in the column that has the last names, you will have "Ann" in there from "Mary Ann" or "Van" from the last name "Van Atta" You would then have "Mary Ann's" Last name in a third column as well as "Atta" in that same column and Jr and Sr. Obviously with this, I couldn't use a formulas to have the last names column be first since you have part of a first name in there. Is there some type of workaround I can use for this?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I feel your pain!

Unfortunately, programming isn't magic, it is very literal. It can only do what you tell it to.
So, if you can not write down on pen and paper all the exact rules it should follow, then you aren't really going to be able to program anything to do it.

This is a common problem I see often (and have experienced myself). It is hard to clean up badly formatted data.
Usually, the best you can do it to program something that handles most of the cases, and then handle the rest manually.
Or, try to get the data provider to change the data format into something that is more usable!
 
Last edited:
Upvote 0
Hia
How about something like this
Code:
Sub SplitName()
                 
    With Range("G1:G25")
        .Formula = "=IF(ISERROR(LEFT(F1, FIND("" "",F1) - 1)),"""",LEFT(F1, FIND("" "",F1) - 1))"
        .Offset(, 1).Formula = "=IF(ISERROR(RIGHT(F1, LEN(F1)-FIND("" "",F1))),"""",RIGHT(F1, LEN(F1)-FIND("" "",F1)))"
        .Value = .Value
        .Offset(, 1).Value = .Offset(, 1).Value
    End With

End Sub
This looks at column F & puts first name in G & last name(s) in H
 
Upvote 0
Fluff,

That doesn't address the issues they are raising:
Here is the problem: Some people might have a name with a space like "Mary Ann" or "Mary Jane". Another person has a last name with spaces like "Van Atta" and other might have Jr or Sr afgter their last name. The issue with that is in the column that has the last names, you will have "Ann" in there from "Mary Ann" or "Van" from the last name "Van Atta" You would then have "Mary Ann's" Last name in a third column as well as "Atta" in that same column and Jr and Sr. Obviously with this, I couldn't use a formulas to have the last names column be first since you have part of a first name in there. Is there some type of workaround I can use for this?
That will always split the name after the first space. So names like "Mary Ann Smith" would not split properly.
 
Upvote 0
Got you.
Misunderstood the OP, I was thinking of Mary Ann as First name/surname rather than just as first name
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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