Multi-column text file of data to extract data

Need from a text file, extract the numbers in the first column, vb how to operate?

 

We see the following statement in the previous post, but it can not be achieved multi-column text extraction functionality.

Sub addall()

Application.ScreenUpdating = False

Dim arr() As String, i As Long, n As Long, b() As Byte, temp As String, lines() As String, x As Long


ReDim arr (1 To 5, 1 To 65535) 'a two-dimensional array, four, excel have the maximum 65,535,

temp = Dir([a1] & "\*.txt")

While temp > ""

n = n + 1

arr (1, n) = temp 'array (1, n) is a file name

Open [a1] & "\" & temp For Binary As # 1 'used to open a file stored in the channel #

ReDim b (LOF (1)) 'acquired file length, defined as the length of the array

Get # 1,, b 'read the last digit', will open the text file to read array b


Close # 1 'Close Channel # 1

On Error Resume Next 'If the error is out of change error trap


lines = Split (StrConv (b, vbUnicode), vbCrLf) ' create an array, the array contents for the content file: Press the end of the text character array divided by a line feed,
' lines in the array so that each element is a text file the contents of each line. The first line is the lines (0), a second row lines (1), and so on.


arr (2, n) = lines ([b1]) 'arr is a two-dimensional array, arr (1,1) is the name of the first file,
' ARR (2,1) is the first file 7 the contents of the line, arr (3,1) is a content line 9 of the first file, arr (1,1) is a content line 12 of the first file, and so on.

arr(3, n) = lines([c1])

arr(4, n) = lines([d1])

arr(5, n) = lines([e1])

temp = Dir () 'so that the loop end condition is reached

Wend 'end of the cycle

ReDim Preserve arr(1 To 5, 1 To n)

[A2] .Resize (n, 5) = WorksheetFunction.Transpose (arr) 'attached to the table array arr

Application.ScreenUpdating = True
End Sub

<ignore_js_op>  avVcXIVb.rar  (709 Bytes, downloads: 632)

 

 

 

I have uploaded the text file you want to import. Finally, I need to import 8944125214963660509 this field.

Guess you like

Origin www.cnblogs.com/medik/p/11026476.html