suprsnipes
Active Member
- Joined
- Apr 26, 2009
- Messages
- 434
Hi,
I am using the following code that I found but I would like to modify it as follows;
I would like place the data into different columns based on a fixed width of
8,12,16,21,22,25 (starting from 0).
Regards,
suprsnipes
I am using the following code that I found but I would like to modify it as follows;
I would like place the data into different columns based on a fixed width of
8,12,16,21,22,25 (starting from 0).
Code:
Sub GetTextFile()
Dim sFile As String
Dim sInput As String
Dim lFNum As Long
Dim vaFields As Variant
Dim i As Long
Dim lRow As Long
Dim vaStrip As Variant
Const sDELIM = "^" 'Set the delimeter
lFNum = FreeFile
sFile = "\\C8b22801\c\q\130610"
vaStrip = Array(vbLf, vbTab) 'list the text to strip
'Open the file
Open sFile For Input As lFNum
'Loop through the file until the end
Do While Not EOF(lFNum)
Line Input #lFNum, sInput 'input the current line
'remove the unwanted text
For i = LBound(vaStrip) To UBound(vaStrip)
sInput = Replace(sInput, vaStrip(i), "")
Next i
'split the text based on the delimeter
vaFields = Split(sInput, sDELIM)
lRow = lRow + 1
'Write to the worksheet
For i = 0 To UBound(vaFields)
Sheet1.Cells(lRow, i + 1).Value = vaFields(i)
Next i
Loop
Close lFNum
End Sub
Regards,
suprsnipes