Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Breaking up a string

I have an "Address" field in Excel that houses Street address, City, State, &
Zip, separated only by spaces. How do I go about separating strings into New
fields for City, State, and Zip? Is there some kind of VBA code I can use to
separate the larger string?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Breaking up a string

One way:

Select the data and then use DataText To Columns. Check Delimited and
Space as the delimiter. You may however run into problems where you have
spaces in the city name eg "New York"

Hope this helps
Rowan

jayceejay wrote:
I have an "Address" field in Excel that houses Street address, City, State, &
Zip, separated only by spaces. How do I go about separating strings into New
fields for City, State, and Zip? Is there some kind of VBA code I can use to
separate the larger string?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Breaking up a string

If he has commas as he shows, he can use that as the delimiter.

--
HTH

Bob Phillips

"Rowan" wrote in message
...
One way:

Select the data and then use DataText To Columns. Check Delimited and
Space as the delimiter. You may however run into problems where you have
spaces in the city name eg "New York"

Hope this helps
Rowan

jayceejay wrote:
I have an "Address" field in Excel that houses Street address, City,

State, &
Zip, separated only by spaces. How do I go about separating strings

into New
fields for City, State, and Zip? Is there some kind of VBA code I can

use to
separate the larger string?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default Breaking up a string

try this, assuming the string is in column A, and there is a name, address,
city, state, zip and phone.

if there are less, it should still work for you

Sub Macro1()
'
'
'
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
'
Application.ScreenUpdating = False
For xR = LastRow To 1 Step -1

Cells.Replace What:=" ", Replacement:=",", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
' Cells.Replace What:="""", Replacement:="", LookAt:=xlPart, SearchOrder
_
' :=xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False

Next xR
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited,
_
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo
_
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5,
1), Array(6, 1)), _
TrailingMinusNumbers:=True
Range("A1").Select
Columns("A:F").EntireColumn.AutoFit
Application.ScreenUpdating = True

End Sub
--


Gary


"jayceejay" wrote in message
...
I have an "Address" field in Excel that houses Street address, City, State,
&
Zip, separated only by spaces. How do I go about separating strings into
New
fields for City, State, and Zip? Is there some kind of VBA code I can use
to
separate the larger string?



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
Breaking a string of letters Confused Excel Discussion (Misc queries) 2 March 10th 07 11:49 AM
Breaking a string of text Confused Excel Discussion (Misc queries) 4 March 9th 07 02:03 PM
Breaking a string of letters john Excel Discussion (Misc queries) 0 March 8th 07 07:31 PM
Opposite of Concatenate (Breaking apart a string) XMLCimo Excel Worksheet Functions 1 March 5th 06 12:20 AM
Breaking up a string into separate columns Loz Excel Worksheet Functions 5 November 22nd 05 03:08 AM


All times are GMT +1. The time now is 04:10 AM.

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

About Us

"It's about Microsoft Excel"