VBA - foundfiles and referencing specific filenames

steimel386

New Member
Joined
Jan 8, 2009
Messages
33
Hey everyone,

When I used foundfiles to pull data from a directory and I pull the names of said files it seems like that it pulls the data, and THEN pulls the names. What happens is that later in the macro it is set up to delete out rows that have an empty value for coulmn A, which it does, but leaves the names produced by foundfiles giving me incorrect data.... Does this just happen or is there a way to link the filenames (I don't care if the directory is there or no, whatever is easier) to the corresponding data? I've included part of the macro below, and thanks for your help. (these all run at once by one larger macro with the call function)
Code:
Sub Jan09_NoSpace()
Sheets("Jan09_NoSpace").Select
n = 3
 On Error Resume Next
 With Application.FileSearch
     .LookIn = ThisWorkbook.Path
     .FileType = msoFileTypeExcelWorkbooks
     .SearchSubFolders = True
     .Execute
     For i = 1 To (.FoundFiles.Count - 1)
         Workbooks.Open .FoundFiles(i)
         n = n + 1
         ThisWorkbook.Sheets(1).Cells(n, 164).Value = .FoundFiles(i)
'this is where the name problem seems to come from, and if I move this to the end of the list it simply doesn't pull anything
         With Sheets("WORK(OPT#1)")
ThisWorkbook.Sheets("Jan09_NoSpace").Cells(n, 1).Value = .Range("F1").Value
'etc--------------------------------------------
ThisWorkbook.Sheets("Jan09_NoSpace").Cells(n, 162).Value = .Range("T71").Value
ThisWorkbook.Sheets("Jan09_NoSpace").Cells(n, 163).Value = .Range("Jan '09").Value
         End With
    
         ActiveWorkbook.Close False
NotMe:
     Next
 End With
 
 
Sub Delete_Empty()
    Dim lLastRow As Long, rngToCheck As Range
    With ActiveSheet
        'find the last row in column A
        lLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        
        Set rngToCheck = .Range(.Cells(1, 1), .Cells(lLastRow, 1))
    End With
    
    On Error Resume Next
    rngToCheck.SpecialCells(xlCellTypeBlanks).ListRow.Delete
    On Error GoTo 0
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top