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
373
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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
2,036
Office Version
  1. 2010
Platform
  1. Windows
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
 

Forum statistics

Threads
1,144,364
Messages
5,723,939
Members
422,527
Latest member
TotalBeginner201

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
Top