please help me, this is really frustrating me..
I have a spreadsheet where I need a certain cell ($K$4) to show the number of files within a folder (E.g. C:\Temp) and any and all subfolders below it that contain the value of cell $G$4 within the file name... So far I have been searching online for the past week and can't get very far. I found something that looked promising, but it appears to only count the original folder files that contain the text from $G$4. Below is the VBA that I found and tried to modify myself.... PLEASE HELP. and thank you in advance.
I have a spreadsheet where I need a certain cell ($K$4) to show the number of files within a folder (E.g. C:\Temp) and any and all subfolders below it that contain the value of cell $G$4 within the file name... So far I have been searching online for the past week and can't get very far. I found something that looked promising, but it appears to only count the original folder files that contain the text from $G$4. Below is the VBA that I found and tried to modify myself.... PLEASE HELP. and thank you in advance.
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim FolderPath As String, path As String, count As Integer
With Target
If Not Intersect(Range("G4"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 1).Value = ""
Else
FolderPath = "T:\11 - Personal Folders\Ryan Legg\- Service Manager\"
path = FolderPath & "*" & Range("G4") & "*"
Filename = Dir(path)
Do While Filename <> ""
count = count + 1
Filename = Dir()
Loop
Range("K4").Value = count
End If
Application.EnableEvents = True
End If
End With
End Sub