Here is the code I have that works great, If I create my ASCII file using only the correct variables in the correct order
Private Sub CommandButton1_Click()
Dim fs, f, ts, Line
Folder = Worksheets("TDS Schedule").Range("Folder").Value
File = Worksheets("TDS Schedule").Range("File").Value
LastET = Val(Worksheets("Raw Data").Range("LastET").Value)
LastRow = Val(Worksheets("Raw Data").Range("LastRow").Value)
FlushStage = Val(Worksheets("Raw Data").Range("FlushStage").Value)
MinRate = Val(Worksheets("Raw Data").Range("MinRate").Value)
Application.Calculation = xlCalculationManual
datafile = Folder & "\" & File
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(datafile) Then
Set f = fs.GetFile(datafile)
Set ts = f.OpenAsTextStream(1, -2)
Do While ts.AtEndOfStream <> True
Line = ts.ReadLine
If InStr(1, Line, Chr(34), 1) < 1 Then
Data = Split(Line, ",")
ET = Val(Data(0))
Stage = Val(Data(1))
InjRate = Val(Data(3))
If (ET > LastET) And ((InjRate > MinRate) Or (Stage = FlushStage)) Then
For i = 1 To 6
Worksheets("Raw Data").Cells(LastRow + 2, i + 1).Value = Data(i - 1)
Next i
LastET = ET
LastRow = LastRow + 1
End If
End If
Loop
ts.Close
Else
MsgBox "File does not exist."
End If
Application.Calculation = xlCalculationAutomatic
End Sub
However, what I would like to know is if there is a way to import only selected column from the ASCII file....? For example lets say the ASCII would have data in 15 columns (A:O) is there I way I can reference some cells or a user form to only take the data from columns 1,3,6,8, and 13 (or whatever ones I specify) and have only those columns come in just like the above macro?
Bookmarks