Hi
I have this piece of code which loops through one folder and opens each csv file within it and performs a counta and pastes the results into a sepeate document which then is saved and closed.
Sub Get_Average_Count()
'Define Variables
'Const strFldr As String = "Path2"
Dim strTemplate As String
Dim strFldr As String
Dim strFile As String
Dim wbExtractSize As Workbook
Dim wbCsv As Workbook
Dim wsDealerExtracts As Worksheet
Dim wsMyCsvSheet As Worksheet
Dim lNextRow As Long
'set strFldr variables
strFldr = “c\:Production2\ATX\Outputs\"
'set strFile variables
strFile = Dir(strFldr & "\*.csv")
strTemplate = "Extract_Size_Checker_template.xls"
'set the calculation mode
Application.Calculation = xlCalculationManual
'set the workbook and worksheet
Set wbExtractSize = Workbooks.Open(“c\:Production2\ATX\Outputs\" & strTemplate)
Set wsDealerExtracts = wbExtractSize.Sheets("Dealer Extracts")
'find the next row available in ExtractSize, add two to
lNextRow = 18
'Loop through the csv files
If Len(strFile) > 0 Then
Do
Set wbCsv = Workbooks.Open(Filename:=strFldr & "\" & strFile)
Set wsMyCsvSheet = wbCsv.Sheets(1)
With wsDealerExtracts
.Cells(lNextRow, 6) = strFldr
.Cells(lNextRow, 7) = strFile
.Cells(lNextRow, 8) = WorksheetFunction.CountA(wsMyCsvSheet.Range("A:A"))
End With
'increment to the next row
lNextRow = lNextRow + 1
'close it
wbCsv.Close
'go to next file
strFile = Dir
Application.StatusBar = strFile
Loop Until Len(strFile) = 0
End If
ActiveWorkbook.ActiveSheet.Range("A1").Select
'clean up
Set wbExtractSize = Nothing
Set wbCsv = Nothing
Set wsDealerExtracts = Nothing
Set wsMyCsvSheet = Nothing
End Sub
However i now must change this piece of code so it opens a folder and performs a count on all the files within each of sub folders that are in this folder. However i am stumped and i have no idea how to do thsi. Can anyone help me???
Thank you
Jeskit
Bookmarks