I need to sort a text file before I can loop through the information.
1.Can some one tell me how to do this?
Here's what I have so far:
1.Can some one tell me how to do this?
Here's what I have so far:
Code:
Sub TXTQryTbl()
Dim ConnString As String
Dim qt As QueryTable
Dim strtemp As String
Dim intFN As Long
Dim varFields As Variant
Dim i As Long
Dim lrow As Long
Dim varstrip As Variant
Dim test As String
Dim endstate As String, startstate As String
Const sDelim = vbTab
z = 2
t = 2
test = ActiveWorkbook.Worksheets("Utility").Range(Cells(z, 1), Cells(z, 1)).Value
endstate = ActiveWorkbook.Worksheets("Frm").Range("RRFrm_endstate").Value
startstate = ActiveWorkbook.Worksheets("frm").Range("RRFrm_startstate").Value
varstrip = Array(vbLf, vbTab)
strfilename = "C:\documents and settings\test\desktop\"
sfilename = "test_8_20-8_27_2006.txt"
ConnString = "TEXT;" & strfilename
intFN = FreeFile
Open (strfilename & sfilename) For Input As #intFN
Do While Not EOF(intFN)
'remove text not needed
Line Input #intFN, strtemp
For i = LBound(varstrip) To UBound(varstrip)
If strtemp <> "Cascade Report Data" Then
'strtemp = Replace(strtemp, " ", "")
varDelim = Split(strtemp, vbTab)
End If
If varDelim(0) = CEID Then
If varDelim(5) = UCase(startstate) Then
ActiveWorkbook.Worksheets("report").Range(Cells(t, 1), Cells(t, 1)).Value = varDelim(0)
ActiveWorkbook.Worksheets("report").Range(Cells(t, 2), Cells(t, 2)).Value = varDelim(1)
ActiveWorkbook.Worksheets("report").Range(Cells(t, 3), Cells(t, 3)).Value = varDelim(2)
ActiveWorkbook.Worksheets("report").Range(Cells(t, 4), Cells(t, 4)).Value = varDelim(3)
ActiveWorkbook.Worksheets("report").Range(Cells(t, 5), Cells(t, 5)).Value = varDelim(4)
ActiveWorkbook.Worksheets("report").Range(Cells(t, 6), Cells(t, 6)).Value = varDelim(5)
ActiveWorkbook.Worksheets("report").Range(Cells(t, 7), Cells(t, 7)).Value = varDelim(6)
ActiveWorkbook.Worksheets("report").Range(Cells(t, 8), Cells(t, 8)).Value = varDelim(7)
ActiveWorkbook.Worksheets("report").Range(Cells(t, 9), Cells(t, 9)).Value = varDelim(8)
t = t + 1
End If
End If
Next i
Loop
End Sub