You could use the following - this will allow you to browse to the file to import and then it will import only Approved quotes into the workbook. See attached workbook.
Option Explicit
Sub importQuote(fName As String, delSep As String)
Dim rdLine As String, splitStr, lRow As Long, ws1 As Worksheet
Application.ScreenUpdating = False
On Error GoTo errHandler
Set ws1 = Worksheets("Sheet1")
Open fName For Input Access Read As #1
While Not EOF(1)
Line Input #1, rdLine
If Left(rdLine, 5) <> "Quote" Then
splitStr = Split(rdLine, delSep)
If splitStr(4) = "Approved" Then
lRow = ws1.Cells(Rows.Count, "A").End(xlUp).Row + 1
ws1.Range("A" & lRow).Resize(, 5) = splitStr
End If
End If
Wend
Close #1
Application.ScreenUpdating = True
Exit Sub
errHandler:
MsgBox "Error importing data into excel - error " & Err.Number & _
" - " & Err.Description
Close #1
End Sub
Sub processFile()
Dim fName As String, delSep As String, fullFileName As String
fullFileName = Application.GetOpenFilename("CSV files (*.csv),*.csv", _
1, "Select File to Import", , False)
If fullFileName = vbNullString Then
MsgBox "Please select a valid file to import"
End If
fName = fullFileName: delSep = vbTab
Call importQuote(fName, delSep)
End Sub
Bookmarks