Wednesday, May 27, 2020

Import TextFiles & Text2Column

Sub Import_File()

Dim X As Double
Dim TXT As String

Open "D:\99_Report_Sample\2019_08_26_SUMGL.txt" _
For Input As #1 'Change Directory For File Location'
X = 0

Do While Not EOF(1)
Line Input #1, TXT
Cells(1, 1).Offset(X, 0) = TXT
X = X + 1
Loop
Close #1

End Sub
------------------------------------------------------
Sub Text2Column()

Dim rng As Range
Dim sh As Worksheet

Set sh = Worksheets("GL_WP") '=>Change the sheet Name'
With sh
Set rng = .[A1]
Set rng = .Range(rng, .Cells(.Rows.Count, rng.Column).End(xlUp))
rng.TextToColumns Destination:=rng, DataType:=xlFixedWidth, _
TextQualifier:=xlFixedWidth, _
Tab:=False, _
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, _
FieldInfo:=Array(Array(0, 1), Array(11, 1), Array(41, 1), Array(75, 1), Array(95, 1), _
Array(119, 1), Array(143, 1)), TrailingMinusNumbers:=True
End With

End Sub