Seperate city, state, zip from 1 to 3 cells?

caroutisine

New Member
Joined
Jun 23, 2003
Messages
11
I have an export from an access database that puts the customer number, name, and address into an excel spreadsheet. The problem is that it puts the city, state and zip code into one cell for each customer. I need to sort by state and zip code, so I need to separate the city, state and zip code into three separate cells for each customer. There is no comma between the city and the state, only spaces.

There are a couple of issues that I'm having trouble with to sort this data:

1. The city may have one or more space between the name:
Example:
Fergus Falls MN 56537
or
South San Francisco CA 90025

2. Some of the Zip codes include the zip + 4
Example:
Louisville KY 40232-5070

Is there a way to tell Excel to take the 5 (or 5+4) numbers at the end of the cell entry and insert it into the next column? Then do the same thing with the state abbreviations? The state abbreviations are the only consistent thing in the cells, they are always between the city and the zip code, and are always two letters...can this somehow be used to tell Excel what to do?

Any help would be greatly appreciated.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I took a formula approach because of the issues with Data | Text to Columns when you don't have a distinctive delimiter. Assume the data that you want to split is in A2. Create these formulas:
Code:
B2  =LEN(A2)
C2  =SEARCH(" ?? ",A2,1)
D2  =C2+3
E2  =LEFT(A2,C2-1)
F2  =MID(A2,C2+1,2)
G2  =MID(A2,D2+1,B2-D2)
Fill them down. They worked for me with the examples you gave.

These formulas work by sidestepping the issues of ZIP code length and the number of words in the City. Instead, Columns C and D find the spaces either side of the only constant -- the State abbreviation. Column B helps with the formula in Column G but you may want to incorporate in there instead.

HTH
Denis
 
Upvote 0
The Right and Left Text functions will work for you. But since both zip code forms are used you would have to use an If/Then to find out which form is used in each cell, then use that to implement the right function(s).

For example: = LEFT(RIGHT(C7,5),1) would return the "-" in the long zip coeds in cell C7.

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,215,537
Messages
6,125,390
Members
449,222
Latest member
taner zz

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