get list of files in column based on two cell value

Ali M

Active Member
Joined
Oct 10, 2021
Messages
304
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
hi

I search for macro brings for all files based on two cells. theis directory "

" contains many folders(AL1,AL2,AL3,MAH1,MAHM2,.....) and each folder contains subfolders (JAN,FEB,MAR....) and cell value E2= dropdown contains folders((AL1,AL2,AL3,MAH1,MAHM2,.....),F2= dropdown contains(JAN,FEB,MAR....) . so what I want if I select just E1 the customer then should brings all of files for all subfolders in column A and hyperlink to open when press for any file and if I select E2,F2 together then should show specific files for specific subfolder(F2) for specific folder(E2)

case1 when select E2 then should shows all files whether folder or subfolder
a.xlsm
ABCDEF
1ITEMFILE NAMEFOLDERSUBFOLDER
21MM.AVIALI1
32MM1.MP4
43MU1.MP3
54KK.XLS
65LL.XLSM
76REPORT.PDF
87INV1.PDF
98INV2.PDF
109INV3.PDF
1110INV4.PDF
1211INV5.PDF
1312INV6.PDF
1413INV7.PDF
1514INV8.PDF
List Details
Cells with Data Validation
CellAllowCriteria
E2ListALI1,ALI2,ALI3
F2ListJAN,FEB,MAR

CASE2
when select E2,F2 then should show the only files based on subfolder F2 which is relating the folder In E2
a.xlsm
ABCDEF
1ITEMFILE NAMEFOLDERSUBFOLDER
21MM.AVIALI1JAN
32MM1.MP4
43MU1.MP3
54KK.XLS
65LL.XLSM
76REPORT.PDF
87INV1.PDF
List Details
Cells with Data Validation
CellAllowCriteria
E2ListALI1,ALI2,ALI3
F2ListJAN,FEB,MAR


this is what I have by need mod this code

VBA Code:
Sub getfiles()

    Dim oFSO As Object
    Dim oFolder As Object
    Dim oFile As Object, sf
    Dim i As Integer, colFolders As New Collection, ws As Worksheet
   
    Set ws = ActiveSheet
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFolder = oFSO.GetFolder("D:\files\customers")
   
    colFolders.Add oFolder          'start with this folder
   
    Do While colFolders.Count > 0      'process all folders
        Set oFolder = colFolders(1)    'get a folder to process
        colFolders.Remove 1            'remove item at index 1
   
        For Each oFile In oFolder.Files
           
                ws.Cells(i + 1, 1) = oFile.Name
             
                i = i + 1
           ' End If
        Next oFile

        For Each sf In oFolder.Subfolders
            colFolders.Add sf 'add to collection for processing
        Next sf
    Loop

End Sub
 

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.

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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