Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba courses london - seperating text strings one

Forum home » Delegate support and help forum » Microsoft VBA Training and help » vba courses london - Seperating text strings from one to two columns

vba courses london - Seperating text strings from one to two columns

ResolvedVersion 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 courses

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

VBA tip:

Empty The Clipboard with CutCopyMode

After each Copy/Paste operation in VBA, you should use the following line of code to empty the clipboard. This ensures that the computer memory doesn't overload:

ActiveSheet.Paste
Application.CutCopyMode = False

View all VBA hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.12 secs.