count of excel files in a folder

learning vba

New Member
Joined
Nov 20, 2016
Messages
8
Hi guys,

I have a list of folder path in cust_folder sheet ( about 20 folder path in range A4: A24) i want the below code to loop through each cell in the range A4:A24 and list the count of excel files in Rage B4:B24)

Is there a way to use this code to work like that?
Thank you in advance



Sub sample()


Dim FolderPath As Range, path As String, count As Integer


FolderPath = Range("A4:A10")
' "E:\cust_log\2010\10"
For Each FolderPath In i


path = FolderPath & "\*.docx"


Filename = Dir(path)


Do While Filename <> ""
count = count + 1
Filename = Dir()
Loop


Range("QB" & i).Value = count
'MsgBox count & " : files found in folder"

Next FolderPath



End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Code:
[COLOR=darkblue]Sub[/COLOR] sample()
    
    [COLOR=darkblue]Dim[/COLOR] FolderPath [COLOR=darkblue]As[/COLOR] Range, counter [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR], strFile [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    
    [COLOR=green]' "E:\cust_log\2010\10"[/COLOR]
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] FolderPath [COLOR=darkblue]In[/COLOR] Range("A4:A10")
        counter = 0
        strFile = Dir(FolderPath & "\*.xls*")
        [COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]Until[/COLOR] strFile = ""
            counter = counter + 1
            strFile = Dir
        [COLOR=darkblue]Loop[/COLOR]
        FolderPath.Offset(,1).Value = counter
    [COLOR=darkblue]Next[/COLOR] FolderPath
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,337
Members
448,568
Latest member
Honeymonster123

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