L
Legacy 93538
Guest
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.
<!-- BEGIN TEMPLATE: bbcode_code -->
</PRE><!-- END TEMPLATE: bbcode_code -->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???
Thanks
Jessicaseymour
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.
<!-- BEGIN TEMPLATE: bbcode_code -->
Code:
<STYLE>.alt2 font {font: 11px monospace !important;color: #333 !important;}</STYLE>
Sub Get_Average_Count()
'********************************************************************
'Opens the extract size checker document
'Loops through the Averagedata folder
'Takes a count of all files in the folder
'Places the result into the extract size checker document
'JS - 17/01/2011
'********************************************************************
'Define Variables
'Const strFldr As String = "Path3"
Dim strFldr As String
Dim strFile As String
Dim wbExtractSize As Workbook
Dim wbCsv As Workbook
Dim wsAverageExtracts As Worksheet
Dim wsMyCsvSheet As Worksheet
Dim lNextRow As Long
'set strFldr variables
strFldr = Path3
'set strFile variables
strFile = Dir(strFldr & "\*.csv")
'set the calculation mode
Application.Calculation = xlCalculationManual
'set the workbook and worksheet
Set wbExtractSize = ActiveWorkbook
Set wsAverageExtracts = wbExtractSize.Sheets("Average 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 wsAverageExtracts
.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
'Close and Save document
ActiveWorkbook.ActiveSheet.Range("A1").Select
ActiveWorkbook.SaveAs Filename:=Path14 & "Extract_Size_Checker_" & bMthno & "_" & bYear & ".xls)"
ActiveWorkbook.Close
'clean up
Set wbExtractSize = Nothing
Set wbCsv = Nothing
Set wsAverageExtracts = Nothing
Set wsMyCsvSheet = Nothing
End Sub
Thanks
Jessicaseymour