Hi,

I have the below vba code which reads in a tab delimited text file fine. The issue however is the length of time it takes as the file is in excess of 500mb. Basically in this example I only want to bring back the records where the first column is in range B5. Is there a slick way this can run much faster?

Option Explicit

Sub TestImport()
    Call ImportTextFile(Sheet1.Range("B1"), vbTab, Sheet2.Range("A4"))
End Sub

Public Sub ImportTextFile(strFileName As String, strSeparator As String, rngTgt As Range)
    Dim lngTgtRow As Long
    Dim lngTgtCol As Long
    Dim varTemp As Variant
    Dim strWholeLine As String
    Dim intPos As Integer
    Dim intNextPos As Integer
    Dim intTgtColIndex As Integer


    Dim wks As Worksheet
    
    Set wks = rngTgt.Parent
    
    intTgtColIndex = rngTgt.Column
    lngTgtRow = rngTgt.Row
    
    Open strFileName For Input Access Read As #1
    
    While Not EOF(1)
        Line Input #1, strWholeLine
        
        varTemp = Split(strWholeLine, strSeparator)
    
        
        If varTemp(0) = Range("B2") Then
            If IsDate(varTemp(2)) = Range("B2") Then
                If CDate(varTemp(2)) >= #1/1/2015# And CDate(varTemp(2)) <= #1/1/2017# Then
                    wks.Cells(lngTgtRow, intTgtColIndex).Resize(, UBound(varTemp) + 1).Value = varTemp
                    lngTgtRow = lngTgtRow + 1
                End If
            End If
        End If
        
    
    Wend
    
    Close #1
    Set wks = Nothing
    

End Sub