Hi

I was wondering if somebody could help me modify this code I found doing a search on Google. I need the code to be able to search subfolders.

I am using Excel 2010

Many Thanks

Private Function CountFiles()
    strDirectory = "D:"
    strDestFolder = "E:"
    strExt = "mp3"
    Dim myfilesystemobject As Object
    Dim myfiles As Object
    Dim myfile As Object
    Dim rng As Range
     
    Set rng = ThisWorkbook.ActiveSheet.Range("A1:A4") 'set this to the range of your filtered list
    Set myfilesystemobject = CreateObject("Scripting.FileSystemObject")
    Set myfiles = myfilesystemobject.GetFolder(strDirectory).Files
    For Each cell In rng
        For Each myfile In myfiles
            If Not IsNull(cell.Value) Then
                If myfile = strDirectory & "\" & cell.Value Then
                    Stop
                    With myfile
                        .Copy strDestFolder & "\" & myfile.Name
                    End With
                Else
                End If
            End If
        Next myfile
    Next cell
End Function