Excel 2010 vb script not working correctly

Guys, I have a piece of vb script that is suppose to look into a specific folder read each of the files in there ending with extension ".PRN" then import the contents of these files into an excel workbook. What is happening is that it is partially working I get no errors but when I double check what the script has ran against the files in the folder there are plenty missing. But I am unsure why they are missing.

Can anyone hold any ideas as to why this is the case.

Public Sub Import(cPath As String)
    Dim strFile               As String
    Dim strData               As String
    Dim intFN                 As Integer
    Dim rng                   As Range
    Dim wks                   As Worksheet
    Dim vData                 As Variant
   
    Set wks = ActiveWorkbook.Worksheets("Import")
    Set rng = wks.Range("A1")
    strFile = Dir(cPath & "*.prn")
    Application.ScreenUpdating = False
   
    Sheets("Import").Select
    Cells.Select
    Selection.ClearContents
    Sheets("Main").Select
   
    Do Until Len(strFile) = 0
        intFN = FreeFile
        Open cPath & strFile For Input As #intFN
        strData = Input(LOF(intFN), #intFN)
        Close intFN
        vData = Split(strData, vbCrLf)
        wks.Range(rng, rng.Offset(UBound(vData))).Value = WorksheetFunction.Transpose(vData)
        'rng.Value = Left(strFile, Len(strFile) - 4)
        Set rng = rng.Offset(1, 0)
        strFile = Dir()
    Loop

    Columns("A:A").Select
    ActiveWorkbook.Worksheets("Import").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Import").Sort.SortFields.Add Key:=Range("A1:A1048576" _
                                                                       ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Import").Sort
        .SetRange Range("A1:A1048576")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
   
    End With
    Range("A1").Select


    Application.ScreenUpdating = True
End Sub


Regards
DarrenJacksonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DarrenJacksonAuthor Commented:
Here is a sample of 1 of the files where it only uploaded partially
Sample.prn
0
Rgonzo1971Commented:
Hi,

pls try

    Do Until Len(strFile) = 0
         intFN = FreeFile
         Open cPath & strFile For Input As #intFN
         strData = Input(LOF(intFN), #intFN)
         Close intFN
         vData = Split(strData, vbCrLf)
         wks.Range(rng, rng.Offset(UBound(vData))).Value = WorksheetFunction.Transpose(vData)
         'rng.Value = Left(strFile, Len(strFile) - 4)
         Set rng = rng.Offset(UBound(vData), 0)
         strFile = Dir()
     Loop

Open in new window

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DarrenJacksonAuthor Commented:
Thanks for this let me test it
0
DarrenJacksonAuthor Commented:
perfect thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.