vba courses london - seperating text strings one
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

resolvedResolved · Low Priority · Version Standard

replyReply Thu 15 Feb 2007, 11:38Delegate Claire said...

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?

For upcoming training course dates see: Pricing & availability

replyReply Thu 15 Feb 2007, 13:30Trainer Garry said...

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.


 

Vba tip:

Stop Screen Flickering When Running Code

Running VBA code may cause the screen to flicker as the monitor is the slowest part of the program and cannot keep up with the very fast changes taking place.

To switch off the screen until the program is run enter the following code line:

Application.ScreenUpdating = False

The screen comes on automatically on completion of the program.

View all VBA hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard