text column

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Text to column

Text to column

resolvedResolved · Medium Priority · Version 2003

Ferdous has attended:
Excel VBA Intro Intermediate course

Text to column

What is the correct syntaxt for applying text to column on Visual Basic?

RE: Text to column

Hi Ferdous

Thanks for the question.

The easiest way to confirm this syntax is to record it but its not the most clear code.

A simple example of dividing text into 3 columns with commas seperating each item looked like:

    
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, 2), Array(3, 1)), _
TrailingMinusNumbers:=True



The most confusing part of it is the FieldInfo. It requires an array to be built with pairs of values for each column. The first value is the column number the second the data type.

Data Types are

1 = xlTextFormat. Text
2 = xlMDYFormat. MDY Date
3 = xlDMYFormat. DMY Date
4 = xlYMDFormat. YMD Date
5 = xlMYDFormat. MYD Date
7 = xlDYMFormat. DYM Date
8 = xlYDMFormat. YDM Date
9 = xlSkipColumn. Skip Column

I hope that helps. Let me know how you get on.

Laura GB

 

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.


 

Excel tip:

Sorting data stored in rows

Primarily Excel is set up to sort data that is stored in columns rather than rows.

It is possible to get Excel to sort data stored in rows however.

Click in the row you want to sort, or select the cells in the rows you wish to sort.

Go to Data - Sort, then go to the Options button in the bottom left corner of the Sort dialogue box.

View all Excel hints and tips


Server loaded in 0.08 secs.