#1   Report Post  
gbeard
 
Posts: n/a
Default text to columns

I have a column whose cells contain an address and city in each cell. I'm
trying to separate the address from the city. Each cell has a different
length of address, but the same city name. Is it possible to, or what is
the easiest way, to separate the address and the city?

Here is a sample of my data:

A B
3700 Chestnut Pasadena
42 N. Hill Pasadena

I want it to be

A B
3700 Chestnut Pasadena
42 N. Hill Pasadena

--
Gary Beard


  #2   Report Post  
gbeard
 
Posts: n/a
Default

Can I reverse the cell so the city is first and then separate the cell based
on the length of the city name?

--
Gary Beard


  #3   Report Post  
Biff
 
Posts: n/a
Default

Hi!

You could use T to C but then afterwards you'd have to concatenate the
components of the address less the city.

Here's an alternative:

A1 = 3700 Chestnut Pasadena

Formula in B1:

=LEFT(A1,FIND("[",SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1,"
","")))))

Returns: 3700 Chestnut

Formula in C1:

=MID(A1,FIND("[",SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1,"
",""))))+1,255)

Returns: Pasadena

After you get all the addresses parsed select all the formulas in columns B
and C and do a Copy/Paste Special/Values then if you want, you can delete
the original list.

Biff

"gbeard" wrote in message
...
Can I reverse the cell so the city is first and then separate the cell
based on the length of the city name?

--
Gary Beard



  #4   Report Post  
Biff
 
Posts: n/a
Default

NB:

You said: "Each cell has a different length of address, but the same city
name."

Based on your example, the city name is one word. If the city names are more
than one word:

New York
Kansas City
St. Louis

Then those formulas won't work and maybe Text to Columns is your best
solution.

Biff

"Biff" wrote in message
...
Hi!

You could use T to C but then afterwards you'd have to concatenate the
components of the address less the city.

Here's an alternative:

A1 = 3700 Chestnut Pasadena

Formula in B1:

=LEFT(A1,FIND("[",SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1,"
","")))))

Returns: 3700 Chestnut

Formula in C1:

=MID(A1,FIND("[",SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1,"
",""))))+1,255)

Returns: Pasadena

After you get all the addresses parsed select all the formulas in columns
B and C and do a Copy/Paste Special/Values then if you want, you can
delete the original list.

Biff

"gbeard" wrote in message
...
Can I reverse the cell so the city is first and then separate the cell
based on the length of the city name?

--
Gary Beard





  #5   Report Post  
Biff
 
Posts: n/a
Default

Here's an alternative to my alternative and doesn't matter if the city name
is more than a single word:

A1 = 3700 Chestnut New York

Formula in B1:

=TRIM(SUBSTITUTE(A1,"New York",""))

Returns: 3700 Chestnut

Formula in C1:

=MID(A1,SEARCH("new york",A1),255)

Returns: New York

The formula in c1 is kind of redundant if all the city names are the same!
You could just manually type one city name and then copy.

Biff

"Biff" wrote in message
...
NB:

You said: "Each cell has a different length of address, but the same city
name."

Based on your example, the city name is one word. If the city names are
more than one word:

New York
Kansas City
St. Louis

Then those formulas won't work and maybe Text to Columns is your best
solution.

Biff

"Biff" wrote in message
...
Hi!

You could use T to C but then afterwards you'd have to concatenate the
components of the address less the city.

Here's an alternative:

A1 = 3700 Chestnut Pasadena

Formula in B1:

=LEFT(A1,FIND("[",SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1,"
","")))))

Returns: 3700 Chestnut

Formula in C1:

=MID(A1,FIND("[",SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1,"
",""))))+1,255)

Returns: Pasadena

After you get all the addresses parsed select all the formulas in columns
B and C and do a Copy/Paste Special/Values then if you want, you can
delete the original list.

Biff

"gbeard" wrote in message
...
Can I reverse the cell so the city is first and then separate the cell
based on the length of the city name?

--
Gary Beard









  #6   Report Post  
gbeard
 
Posts: n/a
Default

Biff,
In the formula you wrote:

=LEFT(A1,FIND("[",SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1,"
","")))))

What does the "[" do?

--
Gary Beard


  #7   Report Post  
Biff
 
Posts: n/a
Default

Hi!

The [ character is used as a "marker". It marks the spot of the last
instance of the space character then instead of searching for a space, the
formula searches for [ since it is now a unique character as opposed to the
space character.

Not real clear is it?

Try this:

LEN(A1)-LEN(SUBSTITUTE(A1," ",""))

Counts the number of spaces in the string = 2

SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))

Substitutes the 2nd instance of space with [ so that the string looks like
this to the formula:

3700 Chestnut[Pasadena

FIND("[",SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))

Returns the position of [ in the string = 14. This is the value used in the
LEFT function as to how many characters to return. Also, I goofed up in that
I should have subtracted 1 from that value because we only want characters
to the right of the 14th position and not including the 14th position, so:

FIND("[",SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))-1


=LEFT(A1,FIND("[",SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1,"
",""))))-1)

Reduced to what it actually does:

=LEFT(A1,13)

Return 13 characters starting from the left in the string of cell A1.

Biff

"gbeard" wrote in message
m...
Biff,
In the formula you wrote:

=LEFT(A1,FIND("[",SUBSTITUTE(A1," ","[",LEN(A1)-LEN(SUBSTITUTE(A1,"
","")))))

What does the "[" do?

--
Gary Beard



  #8   Report Post  
gbeard
 
Posts: n/a
Default

Biff,
Many thanks. I've seen that in different array's and never could find
information on it. Thanks again!

--
Gary Beard


  #9   Report Post  
gbeard
 
Posts: n/a
Default

Biff,
I'm getting a #VALUE! error with this array. I can't pinpoint the problem
though...any ideas?

--
Gary Beard


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text to Columns / Importing Data John Thomson Excel Discussion (Misc queries) 0 May 4th 05 08:21 PM
Sort or Filter option? Mcobra41 Excel Worksheet Functions 3 February 23rd 05 07:22 PM
Text to Columns - moves text up Stoofer Excel Discussion (Misc queries) 2 February 19th 05 10:04 PM
Text To Columns Mike Excel Worksheet Functions 3 December 31st 04 11:22 PM
How do I compare two columns on seperate sheets and replace text . hag400 Excel Worksheet Functions 1 December 28th 04 02:32 PM


All times are GMT +1. The time now is 11:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"