98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft VBA Training and help » vba courses london - Seperating text strings from one to two columns | VBA forum
vba courses london - Seperating text strings from one to two columns | VBA forum
Resolved · Low Priority · Version Standard
Claire has attended:
No courses
Seperating text strings from one to two columns
I have been asked to write a macro to split address data entered in one column into two, with the house name/number and street in one column, and the town in another. Postcode not included. How can I do this?
RE: seperating text strings from one to two columns
did you know there is actually a function for this: for example
lets say you have a database of 4000 songs all in column A.
ie, animals - house of the rising sun
you wanted to replace the hyphens for a column.
Denis replied with this solution
Highlight all of your cells with the data.
Select the topmost cell in the column, e.g. A1
Hold CTRL+SHIFT and then press the down arrow.
OK, once we've done that, go to "Data" menu and select "Text To Columns".
On the Text To Columns window, select "Delimited" and then hit "Next".
In the following window, choose "other" for type of delimiter and use the minus/hyphen sign -
Hit Finish.
Now you will have two columns, from your example, the first column will contain data like "Animals" and the other column will contain the data " House of The Rising Sun". (note the SPACE in front of "House")
To get rid of that SPACE we're going to use the TRIM function.
In cell C1 (or the column to the right of the song titles) type in this formula.
=TRIM(B1)
Then double-click on that little black box on the excel cursor to copy the formula down the whole range. Any spaces at the start or end of the text string will be removed.
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
VBA tip:Stuck in a Code LoopIf you ever get stuck in an infinite code loop when programing in VBA use |