У вас отсутствуют операторы END IF и L OOP, и здесь переменная должна быть txt
InStr(Left(text, 4), "1234") > 0
Исправлена и теперь, надеюсь, работает так, как вы и планировали
Sub IMPORTAR2()
Dim myDir As String, fn As String, txt As String, a(), n As Long, i As Long, ff As Integer, j As Long
myDir = "C:\Users\epontes\Desktop\TDFA 13228 CDP\" '<- Mude de acordo com a necessidade
fn = Dir(myDir & "*.*")
Do While fn <> ""
ff = FreeFile
Open myDir & "\" & fn For Input As #ff
Do While Not EOF(ff)
Line Input #ff, txt
If InStr(Left(txt, 4), "1234") > 0 Then
n = n + 1: ReDim Preserve a(1 To n)
a(n) = Split(txt, vbTab)
End If
Loop
Close #ff
fn = Dir()
Loop
MsgBox n & " Matched"
With ThisWorkbook.Sheets(2).Range("a1")
For i = 1 To n
For j = 0 To UBound(a(i))
.Offset(i, j + 1) = a(i)(j)
Next j
Next
End With
End Sub
Но нет нужно построить массив, просто напишите строки, как вы найдете их
Sub IMPORTAR()
Dim myDir As String, fn As String, txt As String, a As Variant
Dim n As Long, i As Long, ff As Integer
myDir = "C:\Users\epontes\Desktop\TDFA 13228 CDP\" '<- Mude de acordo com a necessidade
fn = Dir(myDir & "*.*")
With ThisWorkbook.Sheets(2).Range("a1")
Do While fn <> ""
ff = FreeFile
Open myDir & "\" & fn For Input As #ff
Do While Not EOF(ff)
Line Input #ff, txt
If StrComp(Left(txt, 4), "1234", 1) = 0 _
Or StrComp(Left(txt, 4), "FPC9", 1) = 0 Then
n = n + 1
a = Split(txt, vbTab)
' output
For i = 0 To UBound(a)
.Cells(n, i + 1) = a(i)
Next
End If
Loop
Close #ff
fn = Dir()
Loop
End With
MsgBox "Finished"
End Sub