Show AllShow All

TextToColumns Method

Parses a column of cells that contain text into several columns.

expression.TextToColumns(Destination, DataType, TextQualifier, ConsecutiveDelimiter, Tab, Semicolon, Comma, Space, Other, OtherChar, FieldInfo, DecimalSeparator, ThousandsSeparator, TrailingMinusNumbers)

expression    Required. An expression that returns one of the objects in the Applies To list.

Destination    Optional Variant. A Range object that specifies where Microsoft Excel will place the results. If the range is larger than a single cell, the top left cell is used.

DataType   Optional XlTextParsingType. The format of the text to be split into columns.

TextQualifier   Optional XlTextQualifier.

ConsecutiveDelimiter    Optional Variant. True to have Microsoft Excel consider consecutive delimiters as one delimiter. The default value is False.

Tab    Optional Variant. True to have DataType be xlDelimited and to have the tab character be a delimiter. The default value is False.

Semicolon    Optional Variant. True to have DataType be xlDelimited and to have the semicolon be a delimiter. The default value is False.

Comma    Optional Variant. True to have DataType be xlDelimited and to have the comma be a delimiter. The default value is False.

Space    Optional Variant. True to have DataType be xlDelimited and to have the space character be a delimiter. The default value is False.

Other    Optional Variant. True to have DataType be xlDelimited and to have the character specified by the OtherChar argument be a delimiter. The default value is False.

OtherChar    Optional Variant (required if Other is True). The delimiter character when Other is True. If more than one character is specified, only the first character of the string is used; the remaining characters are ignored.

FieldInfo    Optional Variant. An array containing parse information for the individual columns of data. The interpretation depends on the value of DataType. When the data is delimited, this argument is an array of two-element arrays, with each two-element array specifying the conversion options for a particular column. The first element is the column number (1-based), and the second element is one of the xlColumnDataType constants specifying how the column is parsed.

DecimalSeparator    Optional String. The decimal separator that Microsoft Excel uses when recognizing numbers. The default setting is the system setting.

ThousandsSeparator    Optional String. The thousands separator that Excel uses when recognizing numbers. The default setting is the system setting.

TrailingMinusNumbers   Optional Variant. Numbers that begin with a minus character.

The following table shows the results of importing text into Excel for various import settings. Numeric results are displayed in the rightmost column.

System decimal separator System thousands separator Decimal separator value Thousands separator value Original text Cell value (data type)
Period Comma Comma Period 123.123,45 123,123.45 (numeric)
Period Comma Comma Comma 123.123,45 123.123,45 (text)
Comma Period Comma Period 123,123.45 123,123.45 (numeric)
Period Comma Period Comma 123 123.45 123 123.45 (text)
Period Comma Period Space 123 123.45 123,123.45 (numeric)

Example

This example converts the contents of the Clipboard, which contains a space-delimited text table, into separate columns on Sheet1. You can create a simple space-delimited table in Notepad or WordPad (or another text editor), copy the text table to the Clipboard, switch to Microsoft Excel, and then run this example.

Worksheets("Sheet1").Activate
ActiveSheet.Paste
Selection.TextToColumns DataType:=xlDelimited, _
    ConsecutiveDelimiter:=True, Space:=True