Looping through a directory to generate a report

KOsborn_13

New Member
Joined
Oct 20, 2017
Messages
4
Good afternoon.
I'm hoping you all can help me (again).
I have a directory that is a repository for forms created in excel. All the forms have the same format. Re repository may contain hundreds of forms in various stages of completion. A form is "complete" when all the required reviewers have signed off via inputting their name in a password protected cell.

I'd like to create a "Status" file that, when clicking the "run report" button, will search each of the files in the directory and populate File name, Signature 1, Signature 2, Signature 3, Signature 4, and Status in columns B thru G.

Please assume the form hold this information in cells B5, D20, D24, E40, E44, and AD47 respectively.

I appreciate any help you can provide.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Maybe something like this:


For this to work put the processing file in the same folder....


Code:
Sub LoopThroughDirectory()
Dim fName As String, fPath As String, wb As Workbook, sh As Worksheet
Set sh = ActiveSheet
fPath = ThisWorkbook.Path
If Right(fPath, 1) <> "\" Then fPath = fPath & "\"
fName = Dir(fPath & "*.xls*")
    Do While fName <> ""
        If fName <> ThisWorkbook.Name Then
            Lrow = sh.Cells(Rows.Count, "A").End(xlUp).Row
            Set wb = Workbooks.Open(fPathe & fName)
                With wb
                    .Sheets(1).Range("B5").Copy sh.Range("A" & Lrow + 1)
                    .Sheets(1).Range("D20").Copy sh.Range("A" & Lrow + 1)
                    .Sheets(1).Range("D24").Copy sh.Range("A" & Lrow + 1)
                    .Sheets(1).Range("E40").Copy sh.Range("A" & Lrow + 1)
                    .Sheets(1).Range("E44").Copy sh.Range("A" & Lrow + 1)
                    .Sheets(1).Range("AD47").Copy sh.Range("A" & Lrow + 1)
                    .Close False
                End With
            fName = Dir
        End If
    Loop
End Sub

Or you could pass values directly like this rather then copy / paste
Code:
sh.Range("A" & Lrow + 1) = wb.Sheets(1).Range("B5")
 
Upvote 0
Matt,
This seems to put me in a loop. As I tried to reverse engineer what you wrote I realized that I left out a vital bit of information. The workbook has 5 sheets. The sheet I want to interrogate is titled "Form_4.09c8".
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
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