I'm trying to count number of rows into files from some folders and sub folders. Folders and sub folders paths are written in a G column.
Sub CountRows()
Dim wbSource As Workbook, wbDest As Workbook
Dim wsSource As Worksheet, wsDest As Worksheet
Dim strFolder As String, strFile As String
Dim lngNextRow As Long, lngRowCount As Long
Dim LastRow
Dim cl As Range
Application.ScreenUpdating = False
Set wbDest = ActiveWorkbook
Set wsDest = wbDest.ActiveSheet
LastRow = wsDest.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For Each cl In wsDest.Range("G11:G" & LastRow)
strFolder = cl.Value
strFile = Dir(strFolder & "/")
lngNextRow = 11
Do While Len(strFile) > 0
Set wbSource = Workbooks.Open(Filename:=strFolder & "/" & strFile)
Set wsSource = wbSource.Worksheets(1)
lngRowCount = wsSource.UsedRange.Rows.Count
wsDest.Cells(lngNextRow, "F").Value = lngRowCount - 1
wbSource.Close savechanges:=False
lngNextRow = lngNextRow + 1
strFile = Dir
Loop
Next cl
...
The result must be inserted in a column F. Maybe some one could explain, please, what is wrong with this loop, because count of rows in each file repeats in column F by number of directories.
For example, if I have 1 folder with 3 files, in column G I will have 3 directories ( 1 directory for each from 3 files C:\Users\Desktop\vba_files\ etc.), then I will get 3 numbers in column F that are a count of rows in each workbook from folder C:\Users\Desktop\vba_files\, but each count repeated 3 times (by number of directories).
It looks in a following way:
wsDest
? – simpLE MAnLastRow
? Also, I would replacelngNextRow = 11
bylngNextRow = wsDest.Range("F" & wsDest.Rows.Count).End(xlup).Row + 1
– simpLE MAn