loop through all folders and sub folders looking for a certain partial file name and copying a certain tab name into a master sheet

jordanburch

Active Member
Joined
Jun 10, 2016
Messages
417
Office Version
  1. 2016
Hi All,

Looking for code that loops through all folders and looks for a file containing the partial name of Certification Statement and then if it finds that partial file name it then looks for the tab name of cleared - cleared to and then it copies all of that data into a master workbook into one sheet and keeps adding it to the last row and goes downward. I cant seem to find anything that suits that need. Does anyone have any code like that or ideas?

Jordan
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I suggest you do this in stages. You have an number of steps:
1: list all the file names within set fo folders and subfolders
2: Find which names match your partial string
3: open each of these files
4: find the correct tab
5: copy the data to master workbook
Each of these steps if fairly straight forward. you will need to give a lot more detail to complete the whole process. this code should do the first step. Note you must add a reference to "Microsoft Scripting Runtime" in the VBA references otherwise you will get an error and it won't work
VBA Code:
Sub tst()
' you must add a reference to "Microsoft scripting runtime" in the VBA references
    Dim FSO As New FileSystemObject
    Dim myFolder As Folder
    Dim mySubFolder As Folder
    Dim myFile As File
 i = 1
spath = ActiveWorkbook.Path
  Set myFolder = FSO.GetFolder(spath)
       For Each mySubFolder In myFolder.SubFolders
              For Each myFile In mySubFolder.Files
               Cells(i, 1) = mySubFolder.Name
               Cells(i, 2) = myFile.Name
               i = i + 1
              Next myFile
       Next mySubFolder
End Sub
Note it puts the folder names in column A and the filenames in column B
Note 2 It uses the activeworkbook folder as the starting place to look for subfolders
 
Upvote 0

Forum statistics

Threads
1,212,938
Messages
6,110,788
Members
448,297
Latest member
carmadgar

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