Hello *benj,
You had the part that writes the file name to the worksheet in an IF statement checking it against the variable Acct. Since Acct was not set to anything, nothing ever matched. I corrected the code.
Sub ListFileNames()
Dim FileName As String
Dim FilePath As String
Dim Valid As Boolean
Dim Wks As Worksheet
R = 1 'Starting Row
Set Wks = Worksheets("Sheet1")
FilePath = "C:\test" & "*.txt"
FileName = Dir(FilePath)
Do While FileName <> ""
Valid = FileName Like "*_######.txt"
If Valid Then
Wks.Cells(R, "A") = FileName
R = R + 1
Acct = Mid(FileName, 6, 6)
End If
FileName = Dir
Loop
End Sub
Bookmarks