Hi,

I have some vba code which extracts data from a tab delimited file.
The code works in terms of finding (for example) where the first column = "123" however it doesn't pull back the records if there is a special character or a character there e.g. "12345-ABCDE" does not work.

I think this is to do with my range selection (as B2 is the driver behind that value).

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 varAll, x As Long, y As Long, t
    Dim wks As Worksheet
    
    t = Timer
    Set wks = rngTgt.Parent
    
    'change this to suit:
    x = 1048000  'max row number of expected result
    y = 20       'number of column of the records
    
    ReDim varAll(0 To x - 1, 0 To y - 1)
    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
                          For i = 0 To UBound(varTemp)
                          varAll(j, i) = varTemp(i)
                          Next
                          j = j + 1
                End If
            End If
        End If
   
    Wend