View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel[_619_] joel[_619_] is offline
external usenet poster
 
Posts: 1
Default Strip records from large textfile with VBA


try this code. I'm using split and texttocolumns.


Private Sub Extract_Records()
Open ThisWorkbook.Path & Application.PathSeparator & _
"Invoice.txt" For Input As #1
RowCount = 1
Do While Not EOF(1)
Line Input #1, Data

'create a zero index base array
splitdata = Split(Data, ",")

'Do not import a record that begins with Total
If Not splitdata(4) = "TOTAL" Then
Range("A" & RowCount) = Data
RowCount = RowCount + 1
End If
Loop
Close #1
LastRow = Range("A" & RowCount).End(xlUp).Row
Range("A1:A" & RowCount).TextToColumns _
Destination:=Range("A1"), _
DataType:=xlDelimited, _
Comma:=True

End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=175311

Microsoft Office Help