简体   繁体   中英

VBA Text to columns FieldInfo

FieldInfo:=Array(Array(0, 5), Array(8, 1))

I am trying to use text to columns fixed width.

For this, I have recorded a macro.

I can understand some of the code since I am new to VBA.

However, The above code is not clear.

Can someone explain what this code does?

FieldInfo:

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 xlColumnDataTypeconstants specifying how the column is parsed.

The example:

Array(Array(3, 9), Array(1, 2))

If the source data has fixed-width columns, the first element of each two-element array specifies the starting character position in the column (as an integer; 0 (zero) is the first character). The second element of the two-element array specifies the parse option for the column as a number from 1 through 9, as listed above.

Source: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-texttocolumns-method-excel

using the source from @Vityata's answer , it means that you made two columns with the two arrays inside the outer array representing the two resulting columns:

Array(0, 5) the 1st column starts at character # 0 (the first char) and the type is YMD date (type 5 )

Array(8, 1) the 2nd column starts at character # 8 (the ninth char = the first column is 8 char wide) The second column's type is General (type 1 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM