Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to split a value in an Excel cell 1

Status
Not open for further replies.

Aydan

Technical User
Dec 14, 2002
51
0
0
BE
Hi, I have a colom where the postal code and cities are entered with a space between them. Now I would like to bring te city over to the colum next to it. Since there are a lot of lines I would like to automate this with a macro. Can anybody help me with this?

 
You don't need VBA to do this - worksheet formulas can do the trick. If your column is A, with as an example the format
###### CCCCCCCCCCCCC
where ###### is the postal code and CCCCCC is the city,
then you can put in B1: "=left(A1,6)"
and in C1: "=right(A1,len(A1)-7)"
after you've copied the formulas down, you can copy the entire columns B and C and "paste-special" them as values. Then you can delete column A.
If your postal code is not a fixed length, you'll have to use the FIND() worksheet function to find the position of the space separating the two, e.g.

B1: "=left(A1,find(" ",A1)-1)"

Rob
[flowerface]
 
Brilliant idea Rob! Thank you so very much!
 
Still a question, everything went well, but now I can not delete the first colum any more since the formulas are reffering to them
 
Sorry, this was a stupid question, I'm not familiar with excel but still. Found the nice feature "Pase special" :)
Thanks again for the tip!


 
Hi , not sure if this will help, but if you have only postal codes and city names , you may try selecting column A,and selecting "DATA" ,"TEXT TO COLUMNS","Delimited" etc.

This splits without formulas.
 
thanks bearjam, I didn't know about this usefull option in Excel. In my case, this could also help doing the job, my problem was already resolved, but good to know for the next time!!
 
Hello... I was just passing by....
... and yes I'm new...
...however, I thought I would say...thnx to bearjam...
...His posting.. allowed me to learn something new...

Tony_813
 
Way to go, bearjam! One of my favorite unknown Excel features!

Data/TextToColumns has some other not-at-all-obvious uses as well. For example, if you've ever had a column of numbers that don't add up correctly because some of the cells are text (even though they LOOK like numbers), Data/TextToColumns can fix the whole column in a flash!

Just hilite the column or part of the column, select Data/TextToColumns, accept all the defaults, and Viola. Fixed!

I use it so much that I made a simple one-line macro and added a button to my button-bar.

Sub TextToNumbers()
Selection.TextToColumns
''' ALL Defaults acceptable.
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top